Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Nov 28, 2019. It is now read-only.

Conversation

@pshemass
Copy link

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.

@mijicd
Copy link
Member

mijicd commented Jul 12, 2019

It looks good, however there's some NullPointerException issue in CI build. Let's fix the cause and proceed with merging this one.

@pshemass
Copy link
Author

It looks good, however there's some NullPointerException issue in CI build. Let's fix the cause and proceed with merging this one.

@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?

@mijicd
Copy link
Member

mijicd commented Jul 15, 2019

@pshemass I'll take a look at it.

@quelgar
Copy link
Contributor

quelgar commented Jul 16, 2019

test:run passes for me too, weird.

a <- b.array
r = Chunk.fromArray(a)
r <- if (l == -1) {
write(Chunk.succeed(0)).const(Chunk.empty)
Copy link
Contributor

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.

Copy link
Author

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 :)

Copy link
Author

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.

Copy link
Member

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.

@pshemass pshemass force-pushed the bugfix/detect_closed_connection branch from 4738a48 to 26f3a3d Compare July 17, 2019 00:59
a <- b.array
r = Chunk.fromArray(a)
r <- if (l == -1) {
ZIO.fail(new IOException("Connection reset by peer"))
Copy link
Contributor

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] = {
Copy link
Contributor

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)
        }

Copy link
Author

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants