Skip to content

Commit

Permalink
[#4477]Fix GoAway issue in Http2 after many requests timeout (#4487)
Browse files Browse the repository at this point in the history
  • Loading branch information
liubao68 authored Sep 2, 2024
1 parent 0863a3b commit 06ff2f0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,11 @@
import org.apache.servicecomb.core.event.InvocationFinishEvent;
import org.apache.servicecomb.core.event.ServerAccessLogEvent;
import org.apache.servicecomb.swagger.invocation.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.vertx.core.http.HttpServerResponse;
import io.vertx.ext.web.RoutingContext;

public class HttpStatusAccessItem implements AccessLogItem<RoutingContext> {
private static final Logger LOGGER = LoggerFactory.getLogger(HttpStatusAccessItem.class);

public static final String EMPTY_RESULT = "-";

@Override
Expand All @@ -40,9 +36,6 @@ public void appendServerFormattedItem(ServerAccessLogEvent accessLogEvent, Strin
return;
}
if (response.closed() && !response.ended()) {
LOGGER.warn(
"Response is closed before sending any data. "
+ "Please check idle connection timeout for provider is properly configured.");
builder.append(EMPTY_RESULT);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ private void tryRunInvocation(Invocation invocation) {
if (throwable != null) {
// Server codec operates on Response. So the filter chain result should be Response and
// will never throw exception.
LOGGER.error("Maybe a fatal bug that should be addressed.", throwable);
// Sometimes Server Codec will throw exception, e.g. Connection Closed.
LOGGER.error("Maybe a fatal bug that should be addressed or codec exception for {}.",
invocation.getInvocationQualifiedName(), throwable);
response = Response.createFail(new InvocationException(Status.INTERNAL_SERVER_ERROR,
new CommonExceptionData("Internal error, check logs for details.")));
}
Expand All @@ -87,7 +89,9 @@ private void tryRunInvocation(Invocation invocation) {
if (throwable != null) {
// Server codec operates on Response. So the filter chain result should be Response and
// will never throw exception.
LOGGER.error("Maybe a fatal bug that should be addressed.", throwable);
// Sometimes Server Codec will throw exception, e.g. Connection Closed.
LOGGER.error("Maybe a fatal bug that should be addressed or codec exception for {}.",
invocation.getInvocationQualifiedName(), throwable);
response = Response.createFail(new InvocationException(Status.INTERNAL_SERVER_ERROR,
new CommonExceptionData("Internal error, check logs for details.")));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,24 @@ public class WebsocketController {
@PostMapping("/websocket")
@Transport(name = CoreConst.WEBSOCKET)
public void websocket(ServerWebSocket serverWebsocket) {
// Client may have not registered message handler, and messages sent may get lost.
// So we sleep for a while to send message.
AtomicInteger receiveCount = new AtomicInteger(0);
serverWebsocket.writeTextMessage("hello", r -> {
});
serverWebsocket.textMessageHandler(s -> {
receiveCount.getAndIncrement();
});
serverWebsocket.closeHandler((v) -> System.out.println("closed"));

new Thread(() -> {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}

serverWebsocket.writeTextMessage("hello", r -> {
});

for (int i = 0; i < 5; i++) {
serverWebsocket.writeTextMessage("hello " + i, r -> {
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.servicecomb.foundation.vertx.http;

import java.io.IOException;
import java.util.Collection;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -116,6 +117,9 @@ public void endResponse() {
}

public void internalFlushBuffer() {
if (serverResponse.closed()) {
return;
}
serverResponse.end();
}

Expand All @@ -130,6 +134,10 @@ public CompletableFuture<Void> sendPart(Part part) {

@Override
public CompletableFuture<Void> sendBuffer(Buffer buffer) {
if (serverResponse.closed()) {
return CompletableFuture.failedFuture(new IOException("Response is closed before sending any data. "
+ "Maybe client is timeout or check idle connection timeout for provider is properly configured."));
}
CompletableFuture<Void> future = new CompletableFuture<>();
serverResponse.write(buffer).onComplete(result -> {
if (result.failed()) {
Expand Down

0 comments on commit 06ff2f0

Please sign in to comment.