Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove un-necessary Http1xServerConnection internal state synchronised access #5143

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 19 additions & 38 deletions src/main/java/io/vertx/core/http/impl/Http1xServerConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,7 @@ private void onContent(Object msg) {
return;
}
Buffer buffer = Buffer.buffer(VertxHandler.safeBuffer(content.content()));
Http1xServerRequest request;
synchronized (this) {
request = requestInProgress;
}
Http1xServerRequest request = requestInProgress;
request.context.execute(buffer, request::handleContent);
//TODO chunk trailers
if (content instanceof LastHttpContent) {
Expand All @@ -212,12 +209,9 @@ private void onContent(Object msg) {

private void onEnd() {
boolean close;
Http1xServerRequest request;
synchronized (this) {
request = requestInProgress;
requestInProgress = null;
close = !keepAlive && responseInProgress == null;
}
Http1xServerRequest request = requestInProgress;
requestInProgress = null;
close = !keepAlive && responseInProgress == null;
request.context.execute(request, Http1xServerRequest::handleEnd);
if (close) {
flushAndClose();
Expand Down Expand Up @@ -468,16 +462,14 @@ public void handleInterestedOpsChanged() {
writable = !isNotWritable();
ContextInternal context;
Handler<Boolean> handler;
synchronized (this) {
if (responseInProgress != null) {
context = responseInProgress.context;
handler = responseInProgress.response()::handleWritabilityChanged;
} else if (webSocket != null) {
context = webSocket.context;
handler = webSocket::handleWritabilityChanged;
} else {
return;
}
if (responseInProgress != null) {
context = responseInProgress.context;
handler = responseInProgress.response()::handleWritabilityChanged;
} else if (webSocket != null) {
context = webSocket.context;
handler = webSocket::handleWritabilityChanged;
} else {
return;
}
context.execute(writable, handler);
}
Expand All @@ -496,14 +488,9 @@ void write103EarlyHints(HttpHeaders headers, PromiseInternal<Void> promise) {
}

protected void handleClosed() {
Http1xServerRequest responseInProgress;
Http1xServerRequest requestInProgress;
ServerWebSocketImpl ws;
synchronized (this) {
ws = this.webSocket;
requestInProgress = this.requestInProgress;
responseInProgress = this.responseInProgress;
}
Http1xServerRequest responseInProgress = this.responseInProgress;
Http1xServerRequest requestInProgress = this.requestInProgress;
ServerWebSocketImpl webSocket = this.webSocket;
if (requestInProgress != null) {
requestInProgress.context.execute(v -> {
requestInProgress.handleException(HttpUtils.CONNECTION_CLOSED_EXCEPTION);
Expand All @@ -514,23 +501,17 @@ protected void handleClosed() {
responseInProgress.handleException(HttpUtils.CONNECTION_CLOSED_EXCEPTION);
});
}
if (ws != null) {
ws.context.execute(v -> ws.handleConnectionClosed());
if (webSocket != null) {
webSocket.context.execute(v -> webSocket.handleConnectionClosed());
}
super.handleClosed();
}

@Override
public void handleException(Throwable t) {
super.handleException(t);
Http1xServerRequest responseInProgress;
Http1xServerRequest requestInProgress;
synchronized (this) {
requestInProgress = this.requestInProgress;
responseInProgress = this.responseInProgress;
if (METRICS_ENABLED && metrics != null) {
requestFailed = true;
}
if (METRICS_ENABLED && metrics != null) {
requestFailed = true;
}
if (requestInProgress != null) {
requestInProgress.handleException(t);
Expand Down