This repository was archived by the owner on Aug 11, 2023. It is now read-only.
This repository was archived by the owner on Aug 11, 2023. It is now read-only.
ServiceResponseHandler uses unsafe queue for returning service responses to caller #261
Open
Description
The ServiceResponseHandler uses a queue to handler ros service requests between nodes. Since the response to a service call is simply a poll from the queue, service responses can become mismatched if a node contains multi-threaded components making the same service call. If the first request does not complete before the second request, the responses will be flipped. A mapping is needed to ensure only the correct responses are returned.
Relevant variable: Line 41
private final Queue<ServiceResponseListener<ResponseType>> responseListeners;
Relevant method: Line 52
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
final ServiceResponseListener<ResponseType> listener = responseListeners.poll();
Preconditions.checkNotNull(listener, "No listener for incoming service response.");
final ServiceServerResponse response = (ServiceServerResponse) e.getMessage();
final ChannelBuffer buffer = response.getMessage();
executorService.execute(new Runnable() {
@Override
public void run() {
if (response.getErrorCode() == 1) {
listener.onSuccess(deserializer.deserialize(buffer));
} else {
String message = Charset.forName("US-ASCII").decode(buffer.toByteBuffer()).toString();
listener.onFailure(new RemoteException(StatusCode.ERROR, message));
}
}
});
}