We have containerized .NET Core application and running in OpenShift.
While running our application from UI we are seeing an error
Underlying connection was closed
Our API is registered with WSO2 and when I run our application using WSO2 gateway through PostMan I see SocketHang Up Error. Below is the error Log
ID: [] [] [2021-11-12 20:07:17,341] ERROR {org.apache.synapse.transport.passthru.SourceHandler} - Content-Length header already present {org.apache.synapse.transport.passthru.SourceHandler}
org.apache.http.ProtocolException: Content-Length header already present
at org.apache.http.protocol.ResponseContent.process(ResponseContent.java:101)
at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:139)
at org.apache.synapse.transport.passthru.SourceResponse.start(SourceResponse.java:179)
at org.apache.synapse.transport.passthru.SourceHandler.responseReady(SourceHandler.java:310)
at org.apache.http.impl.nio.DefaultNHttpServerConnection.produceOutput(DefaultNHttpServerConnection.java:309)
at org.apache.synapse.transport.http.conn.LoggingNHttpServerConnection.produceOutput(LoggingNHttpServerConnection.java:127)
at org.apache.synapse.transport.passthru.ServerIODispatch.onOutputReady(ServerIODispatch.java:87)
at org.apache.synapse.transport.passthru.ServerIODispatch.onOutputReady(ServerIODispatch.java:39)
at org.apache.http.impl.nio.reactor.AbstractIODispatch.outputReady(AbstractIODispatch.java:150)
at org.apache.http.impl.nio.reactor.BaseIOReactor.writable(BaseIOReactor.java:180)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:342)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:316)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:277)
at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:105)
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:586)
at java.lang.Thread.run(Thread.java:748)
TID: [] [] [2021-11-12 20:07:17,342] INFO {org.apache.synapse.transport.passthru.SourceHandler} - Writer null when calling informWriterError {org.apache.synapse.transport.passthru.SourceHandler}
TID: [] [] [2021-11-12 20:07:17,342] ERROR {org.apache.synapse.transport.passthru.SourceHandler} - Unexpected I/O error: java.nio.channels.ClosedChannelException {org.apache.synapse.transport.passthru.SourceHandler}
java.nio.channels.ClosedChannelException
at sun.nio.ch.SocketChannelImpl.ensureWriteOpen(SocketChannelImpl.java:270)
at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:461)
at org.apache.http.nio.reactor.ssl.SSLIOSession.sendEncryptedData(SSLIOSession.
TID: [] [] [2021-11-12 20:07:17,334] DEBUG {org.apache.synapse.transport.http.headers} - http-outgoing-14 << HTTP/1.1 204 No Content {org.apache.synapse.transport.http.headers}
TID: [] [] [2021-11-12 20:07:17,334] DEBUG {org.apache.synapse.transport.http.headers} - http-outgoing-14 << Date: Fri, 12 Nov 2021 12:07:17 GMT {org.apache.synapse.transport.http.headers}
TID: [] [] [2021-11-12 20:07:17,334] DEBUG {org.apache.synapse.transport.http.headers} - http-outgoing-14 << Server: Kestrel {org.apache.synapse.transport.http.headers}
TID: [] [] [2021-11-12 20:07:17,334] DEBUG {org.apache.synapse.transport.http.headers} - http-outgoing-14 << Content-Length: 0 {org.apache.synapse.transport.http.headers}
TID: [] [] [2021-11-12 20:07:17,334] DEBUG {org.apache.synapse.transport.http.headers} - http-outgoing-14 << Set-Cookie: cd1550ebc2ca7854f34f209e62d8deed=a483899cdd89e134e6a0fe6a0f3209f6; path=/; HttpOnly {org.apache.synapse.transport.http.headers}
TID: [] [] [2021-11-12 20:07:17,334] DEBUG {org.apache.synapse.transport.http.headers} - http-outgoing-14 << Cache-control: private {org.apache.synapse.transport.http.headers}
TID: [] [] [2021-11-12 20:07:17,341] ERROR {org.apache.synapse.transport.passthru.SourceHandler} - Content-Length header already present {org.apache.synapse.transport.passthru.SourceHandler}
org.apache.http.ProtocolException: Content-Length header already present
at org.apache.http.protocol.ResponseContent.process(ResponseContent.java:101)
Main method in the API
[HttpGet("Settings/{identifier}/Timestamp")]
public async Task<ActionResult<DateTimeOffset?>> MethodName(string identifier, CancellationToken token)
{
return await _service.MethodName(identifier, token);
}
public async Task<DateTimeOffset?> MethodName(string username, string identifier, CancellationToken token)
{
// code the get userSetting from DB
return userSetting?.somevariable.WithTimeZone(TimeZone);
}
public static DateTimeOffset WithTimeZone(this DateTime time, TimeZoneInfo timeZone)
{
var offset = timeZone.GetUtcOffset(time);
time = time.Kind == DateTimeKind.Unspecified ? time
: new DateTime(time.Ticks, DateTimeKind.Unspecified);
return time - DateTime.MaxValue > offset
? DateTimeOffset.MaxValue.ToOffset(offset)
: new DateTimeOffset(time, offset);
}
Below are the possible causes we analyzed
- This API during sometime returns 204 No Content
- Also backend returning a header called Content-Length:0
- This error is caused only when our app is running on OpenShift. In IIS it works fine.
Is it possible to remove the Content-Length from the response?
Are there any other causes for this Socket hangup error?