Skip to content

Commit b9cd684

Browse files
authored
Merge pull request #3919 from jooby-project/3918
fix(undertow): resolve buffer already freed exception during shutdown
2 parents e3a6d7c + 426ee05 commit b9cd684

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

modules/jooby-undertow/src/main/java/io/jooby/internal/undertow/UndertowGrpcExchange.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.Map;
1212
import java.util.function.Consumer;
1313

14+
import org.xnio.IoUtils;
1415
import org.xnio.channels.StreamSinkChannel;
1516

1617
import io.jooby.rpc.grpc.GrpcExchange;
@@ -144,19 +145,19 @@ public void close(int statusCode, String description) {
144145
try {
145146
if (ch.flush()) {
146147
ch.suspendWrites();
147-
exchange.endExchange();
148+
endExchange();
148149
}
149150
} catch (IOException ignored) {
150151
ch.suspendWrites();
151-
exchange.endExchange();
152+
endExchange();
152153
}
153154
});
154155
responseChannel.resumeWrites();
155156
} else {
156-
exchange.endExchange();
157+
endExchange();
157158
}
158159
} catch (IOException e) {
159-
exchange.endExchange();
160+
endExchange();
160161
}
161162

162163
} else {
@@ -170,4 +171,9 @@ public void close(int statusCode, String description) {
170171
exchange.endExchange();
171172
}
172173
}
174+
175+
private void endExchange() {
176+
IoUtils.safeClose(responseChannel);
177+
IoUtils.safeClose(exchange.getRequestChannel());
178+
}
173179
}

modules/jooby-undertow/src/main/java/io/jooby/internal/undertow/UndertowGrpcInputBridge.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public void request(long n) {
5555
public void cancel() {
5656
demand.set(0);
5757
IoUtils.safeClose(channel);
58-
exchange.endExchange();
5958
}
6059

6160
@Override
@@ -90,7 +89,6 @@ public void handleEvent(StreamSourceChannel channel) {
9089
} catch (Throwable t) {
9190
subscriber.onError(t);
9291
IoUtils.safeClose(channel);
93-
exchange.endExchange();
9492
}
9593
}
9694
}

0 commit comments

Comments
 (0)