Spin Loop when underlying channel is closed
See original GitHub issueHi @marianobarrios, thanks for providing this very useful library!
I try to use it for a https proxy and encountered the following problem: When the wrapped socket was closed while someone still wants to emit data, the TlsChannelImpl.wrapAndWrite(ByteBufferSet)
seems to hang in a endless loop. Example stack dump:
java.lang.Thread.State: RUNNABLE
at sun.security.ssl.SSLEngineImpl.wrap(java.base@17.0.4.1/SSLEngineImpl.java:146)
at sun.security.ssl.SSLEngineImpl.wrap(java.base@17.0.4.1/SSLEngineImpl.java:123)
at tlschannel.impl.TlsChannelImpl.callEngineWrap(TlsChannelImpl.java:411)
at tlschannel.impl.TlsChannelImpl.wrapLoop(TlsChannelImpl.java:393)
at tlschannel.impl.TlsChannelImpl.wrapAndWrite(TlsChannelImpl.java:383)
at tlschannel.impl.TlsChannelImpl.write(TlsChannelImpl.java:368)
at tlschannel.ServerTlsChannel.write(ServerTlsChannel.java:291)
at tlschannel.ServerTlsChannel.write(ServerTlsChannel.java:296)
at tlschannel.ServerTlsChannel.write(ServerTlsChannel.java:301)
at <my code>
The log is filled with
Oct 02 07:50:55 ip-172-31-0-148.eu-central-1.compute.internal java[24592]: 2022/10/02 07:50:54.938 TRACE TlsChannelImpl - engine.wrap() result: [status=CLOSED,handshakeStatus=NOT_HANDSHAKING,bytesProduced=0,bytesConsumed=0]; engine status: NOT_HANDSHAKING; srcBuffer: ByteBufferSet[[java.nio.HeapByteBuffer[pos=14 lim=117 cap=32768]]:0:1], outEncrypted: BufferHolder{name='outEncrypted', allocator=tlschannel.TrackingAllocator@2c83ec10, plainData=false, maxSize=17408, opportunisticDispose=true, buffer=java.nio.DirectByteBuffer[pos=0 lim=17408 cap=17408], lastSize=17408}
Oct 02 07:50:55 ip-172-31-0-148.eu-central-1.compute.internal java[24592]: 2022/10/02 07:50:54.938 TRACE TlsChannelImpl - engine.wrap() result: [status=CLOSED,handshakeStatus=NOT_HANDSHAKING,bytesProduced=0,bytesConsumed=0]; engine status: NOT_HANDSHAKING; srcBuffer: ByteBufferSet[[java.nio.HeapByteBuffer[pos=14 lim=117 cap=32768]]:0:1], outEncrypted: BufferHolder{name='outEncrypted', allocator=tlschannel.TrackingAllocator@2c83ec10, plainData=false, maxSize=17408, opportunisticDispose=true, buffer=java.nio.DirectByteBuffer[pos=0 lim=17408 cap=17408], lastSize=17408}
Oct 02 07:50:55 ip-172-31-0-148.eu-central-1.compute.internal java[24592]: 2022/10/02 07:50:54.938 TRACE TlsChannelImpl - engine.wrap() result: [status=CLOSED,handshakeStatus=NOT_HANDSHAKING,bytesProduced=0,bytesConsumed=0]; engine status: NOT_HANDSHAKING; srcBuffer: ByteBufferSet[[java.nio.HeapByteBuffer[pos=14 lim=117 cap=32768]]:0:1], outEncrypted: BufferHolder{name='outEncrypted', allocator=tlschannel.TrackingAllocator@2c83ec10, plainData=false, maxSize=17408, opportunisticDispose=true, buffer=java.nio.DirectByteBuffer[pos=0 lim=17408 cap=17408], lastSize=17408}
I assume that TlsChannelImpl.wrapAndWrite(ByteBufferSet)
should also check the closed state of the channel because in this case the source buffer will never be consumed.
Please let me know if I can add any additional information.
Issue Analytics
- State:
- Created a year ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Basic Spin Manual
Promela programs consist of processes, message channels, and variables. ... has not reached its closing curly brace, but waits in the loop.
Read more >(PDF) Basic Spin Manual
Spin is a tool for analyzing the logical consistency of concurrent systems, specifically of data communication protocols.
Read more >Chapter 4, Concurrency Patterns in Go
When the stream we're currently looping over is closed, we break out of the loop performing the reads from this channel, and continue...
Read more >Open Loop vs Closed Loop Hydraulics - YouTube
A run down on 2 types of hydraulic systems and how they basically work.
Read more >Large-scale, closed-loop interrogation of neural circuits ...
Large-scale, closed-loop interrogation of neural circuits underlying cognition ... Therefore, the form factor, material, minimum number of channels, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Released (but it will take some time to get to Maven Central, I guess). Thanks for your report and testing!
PS: And for the Java Version Almanac, that I just realized it’s yours, and it’s awesome.
Still up and running without endless loop 👍