-
Notifications
You must be signed in to change notification settings - Fork 29
#109 detect closed client connection #115
base: master
Are you sure you want to change the base?
Conversation
|
It looks good, however there's some |
@mijicd this is on develop somehow. I looked into test and assertion passed. Could you help me with that since I don't have experience with testz? |
|
@pshemass I'll take a look at it. |
|
|
| a <- b.array | ||
| r = Chunk.fromArray(a) | ||
| r <- if (l == -1) { | ||
| write(Chunk.succeed(0)).const(Chunk.empty) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why write a single 0 byte here? I haven't been able to figure it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
damm, I need to push my latest change because I got rid of that. The Idea was that you need to use connection to get exception that is closed already because TCP connection don't know that it's been closed unless you use it. so I send whatever :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@quelgar please look into latest commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe extract it to some helper function as clean-up.
4738a48 to
26f3a3d
Compare
| a <- b.array | ||
| r = Chunk.fromArray(a) | ||
| r <- if (l == -1) { | ||
| ZIO.fail(new IOException("Connection reset by peer")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| val inetAddress = InetAddress.localHost | ||
| .flatMap(iAddr => SocketAddress.inetSocketAddress(iAddr, 13370)) | ||
|
|
||
| def server: IO[Exception, Boolean] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave this branch a run and noticed it doesn't close down the listening socket. This means if you execute test:run a second time in the same sbt session, you get an address already bound error. I think you need to use bracketing to make sure the cleanup happens. Very roughly:
def server: IO[Exception, Boolean] = {
for {
address <- inetAddress
_ <- AsynchronousServerSocketChannel().bracket(_.close.ignore) { server =>
server.bind(address) *> server.accept.bracket(_.close.ignore) { worker =>
worker.read(3) *> worker.read(3)
}
}
} yield false
}.catchSome {
case ex: java.io.IOException if ex.getMessage == "Connection reset by peer" =>
ZIO.succeed(true)
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great catch I will update this.
isOpen is useless in case of detecting if connection was reset by peer. I decided to make decision based on number of bytes that is read from channel. -1 means end-of-stream.