Skip to content

Commit

Permalink
Don't crash on closed channel
Browse files Browse the repository at this point in the history
As seen in production:

    java.nio.channels.CancelledKeyException: null
        at sun.nio.ch.SelectionKeyImpl.ensureValid(SelectionKeyImpl.java:73)
        at sun.nio.ch.SelectionKeyImpl.readyOps(SelectionKeyImpl.java:87)
        at java.nio.channels.SelectionKey.isWritable(SelectionKey.java:312)
        at io.github.erikvanzijst.scalatlsproxy.TlsProxyHandler.process(TlsProxyHandler.scala:175)
        at io.github.erikvanzijst.scalatlsproxy.TlsProxy.run(TlsProxy.scala:28)
  • Loading branch information
erikvanzijst committed Sep 1, 2021
1 parent f5678ad commit 494b882
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class TlsProxyHandler(selector: Selector, clientChannel: SocketChannel, config:
}.get

if (phase == Response)
if (clientKey.isWritable) {
if (clientKey.isValid && clientKey.isWritable) {
serverBuffer.flip()
clientChannel.write(serverBuffer)
serverBuffer.compact()
Expand Down Expand Up @@ -180,7 +180,7 @@ class TlsProxyHandler(selector: Selector, clientChannel: SocketChannel, config:
}

if (phase == Error)
if (clientKey.isWritable) {
if (clientKey.isValid && clientKey.isWritable) {
serverBuffer.flip()
clientChannel.write(serverBuffer)
serverBuffer.compact()
Expand Down

0 comments on commit 494b882

Please sign in to comment.