Skip to content

Commit e2e144d

Browse files
committed
Fix Grizzly on close when error
Signed-off-by: Jorge Bescos Gascon <[email protected]>
1 parent 7ea3893 commit e2e144d

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

containers/grizzly2-http/src/main/java/org/glassfish/jersey/grizzly2/httpserver/GrizzlyHttpContainer.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2022 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2025 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -231,25 +231,29 @@ public void setSuspendTimeout(final long timeOut, final TimeUnit timeUnit) throw
231231
public OutputStream writeResponseStatusAndHeaders(final long contentLength,
232232
final ContainerResponse context)
233233
throws ContainerException {
234-
try {
235-
final javax.ws.rs.core.Response.StatusType statusInfo = context.getStatusInfo();
236-
if (statusInfo.getReasonPhrase() == null) {
237-
grizzlyResponse.setStatus(statusInfo.getStatusCode());
238-
} else {
239-
grizzlyResponse.setStatus(statusInfo.getStatusCode(), statusInfo.getReasonPhrase());
240-
}
234+
if (!grizzlyResponse.isCommitted()) {
235+
try {
236+
final javax.ws.rs.core.Response.StatusType statusInfo = context.getStatusInfo();
237+
if (statusInfo.getReasonPhrase() == null) {
238+
grizzlyResponse.setStatus(statusInfo.getStatusCode());
239+
} else {
240+
grizzlyResponse.setStatus(statusInfo.getStatusCode(), statusInfo.getReasonPhrase());
241+
}
241242

242-
grizzlyResponse.setContentLengthLong(contentLength);
243+
grizzlyResponse.setContentLengthLong(contentLength);
243244

244-
for (final Map.Entry<String, List<String>> e : context.getStringHeaders().entrySet()) {
245-
for (final String value : e.getValue()) {
246-
grizzlyResponse.addHeader(e.getKey(), value);
245+
for (final Map.Entry<String, List<String>> e : context.getStringHeaders().entrySet()) {
246+
for (final String value : e.getValue()) {
247+
grizzlyResponse.addHeader(e.getKey(), value);
248+
}
247249
}
248-
}
249250

250-
return grizzlyResponse.getOutputStream();
251-
} finally {
252-
logger.debugLog("{0} - writeResponseStatusAndHeaders() called", name);
251+
return grizzlyResponse.getOutputStream();
252+
} finally {
253+
logger.debugLog("{0} - writeResponseStatusAndHeaders() called", name);
254+
}
255+
} else {
256+
return null;
253257
}
254258
}
255259

0 commit comments

Comments
 (0)