Skip to content

Conversation

@lgaches
Copy link
Contributor

@lgaches lgaches commented Feb 6, 2017

No description provided.

@codecov-io
Copy link

codecov-io commented Feb 6, 2017

Codecov Report

Merging #105 into master will increase coverage by 0.43%.

@@            Coverage Diff             @@
##           master     #105      +/-   ##
==========================================
+ Coverage   66.18%   66.61%   +0.43%     
==========================================
  Files          29       29              
  Lines        1384     1396      +12     
==========================================
+ Hits          916      930      +14     
+ Misses        468      466       -2
Impacted Files Coverage Δ
Sources/SocksCore/TCPSocket.swift 83.58% <100%> (+1.02%)
Tests/SocksCoreTests/LifetimeTests.swift 82.35% <100%> (+2.35%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b47313f...6177ca1. Read the comment docs.

if closed { return }
stopWatching()
if socket_close(self.descriptor) != 0 {
closed = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below we throw an error saying closeFailed so would setting it to true in the line above be dishonest about the current state of the socket?

@lgaches
Copy link
Contributor Author

lgaches commented Feb 9, 2017

I've tried to improve error handling

stopWatching()
closed = true
if socket_close(self.descriptor) != 0 {
if errno != EBADF {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So basically, closed should be considered true unless it's a bad descriptor, EBADF? I think I'd prefer to set once instead of toggle incase there's some type of observing behavior at one point, maybe something like this

guard socket_close(self.descriptor) == 0 else {
    // bad file descriptor EBADF should still be considered closed ... include reference here
    if errno == EBADF { closed = true }
    throw SocksError(.closeSocketFailed)
}

// set descriptor to -1 to prevent further use
self.descriptor = -1
closed = true

Which brings up another question for me, can we get these two things

  1. a link to docs that show why EBADF is still considered closed
  2. on EBADF, we're considering the socket, but not closing the descriptor w/ -1 and we're throwing. Should it still throw on this error, and should descriptor be set to -1 as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

closed var has to be set to true before trying to close the socket. Otherwise application checking closed var to send or receive data on the socket can be in inconsistent state. I've detected this error running benchmark with MongoKitten. Settings closed earlier prevent communication on closing socket. It's not clear for me how to handle the other error case. Obviously EBADF is clearly closed :-) so descriptor has to be set to -1.

@loganwright loganwright requested a review from vzsg February 9, 2017 16:13
Copy link
Member

@vzsg vzsg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@loganwright loganwright merged commit f4b5414 into vapor-community:master Feb 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants