Thrift transport handling unexpected URI hangs, closes #1484.
This commit is contained in:
parent
f28c11b31c
commit
0c384af9bf
|
@ -29,6 +29,7 @@ import org.elasticsearch.rest.RestChannel;
|
|||
import org.elasticsearch.rest.RestController;
|
||||
import org.elasticsearch.rest.RestResponse;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.rest.StringRestResponse;
|
||||
import org.elasticsearch.rest.XContentRestResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -36,6 +37,8 @@ import java.nio.ByteBuffer;
|
|||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.elasticsearch.rest.RestStatus.*;
|
||||
|
||||
/**
|
||||
* @author kimchy (shay.banon)
|
||||
*/
|
||||
|
@ -54,7 +57,7 @@ public class ThriftRestImpl extends AbstractComponent implements Rest.Iface {
|
|||
}
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
final AtomicReference<org.elasticsearch.thrift.RestResponse> ref = new AtomicReference<org.elasticsearch.thrift.RestResponse>();
|
||||
restController.dispatchRequest(new ThriftRestRequest(request), new RestChannel() {
|
||||
boolean dispatched = restController.dispatchRequest(new ThriftRestRequest(request), new RestChannel() {
|
||||
@Override public void sendResponse(RestResponse response) {
|
||||
try {
|
||||
ref.set(convert(response));
|
||||
|
@ -64,6 +67,14 @@ public class ThriftRestImpl extends AbstractComponent implements Rest.Iface {
|
|||
latch.countDown();
|
||||
}
|
||||
});
|
||||
if (!dispatched) {
|
||||
try {
|
||||
ref.set(convert(new StringRestResponse(BAD_REQUEST, "No handler found for uri [" + request.getUri() + "] and method [" + request.getMethod() + "]")));
|
||||
} catch (IOException e) {
|
||||
// ignore, will not happen... (from convert)
|
||||
}
|
||||
latch.countDown();
|
||||
}
|
||||
try {
|
||||
latch.await();
|
||||
return ref.get();
|
||||
|
|
|
@ -87,6 +87,10 @@ public class SimpleThriftTests {
|
|||
request = new RestRequest(Method.GET, "/_cluster/health");
|
||||
response = client.execute(request);
|
||||
assertThat(response.getStatus(), equalTo(Status.OK));
|
||||
|
||||
request = new RestRequest(Method.GET, "/bogusindex");
|
||||
response = client.execute(request);
|
||||
assertThat(response.getStatus(), equalTo(Status.BAD_REQUEST));
|
||||
}
|
||||
|
||||
private Map<String, Object> parseBody(RestResponse response) throws IOException {
|
||||
|
|
Loading…
Reference in New Issue