I am using the gUPnP AV ControlPoint to browse my MediaServer. This application browses all nodes in advance and uses parallel requests for nodes on the same level. Therefore concurrent requests may occur.
The problem is that the arguments of an earlier request might get overwritten with the values from the latter one. In such a case, the response is wrong (e.g. browsing container "1" and "2" results in two responses for container "2").
After a lot of investigation, I found that the problem occurs in the cyberlink upnp-stack itself. I assume the error is rooted in the "HTTPServerThread" which shares the same "HTTPServer" object among multiple threads. Tracking down the problem has shown that the error occurs somewhere in the "deviceActionControlReceived" method of the "org.cybergarage.upnp.Device" class because synchronizing a part of the method solves the issue:
private void deviceActionControlRecieved(ActionRequest ctlReq, Service service)
{
if (Debug.isOn() == true)
ctlReq.print();
String actionName = ctlReq.getActionName();
Action action = service.getAction(actionName);
if (action == null) {
invalidActionControlRecieved(ctlReq);
return;
}
ArgumentList actionArgList = action.getArgumentList();
ArgumentList reqArgList = ctlReq.getArgumentList();
synchronized(deviceNode) { //synchronizing the next two method calls
try {
actionArgList.setReqArgs(reqArgList);
} catch (IllegalArgumentException ex){
invalidArgumentsControlRecieved(ctlReq);
return;
}
if (action.performActionListener(ctlReq) == false)
invalidActionControlRecieved(ctlReq);
}
}
However, I think this is not an optimal solution but I could not narrow down the error any further (synchronizing later methods and therefore less code did not solve the problem).