Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes crashes when asyncdispatch.adjustTimeout returns a negative value. #11231

Merged
merged 1 commit into from May 15, 2019

Conversation

Projects
None yet
2 participants
@dom96
Copy link
Member

commented May 11, 2019

Code that I used to debug this

The crash that happened before this PR:

tasyncwriteleak.nim(59)  tasyncwriteleak
asyncdispatch.nim(1840)  waitFor
asyncdispatch.nim(1534)  poll
asyncdispatch.nim(1259)  runOnce
ioselectors_kqueue.nim(491) selectInto
selectors.nim(279)       raiseIOSelectorsError
Error: unhandled exception: Invalid argument (code: 22) [IOSelectorsException]

The crash that would happen now:

tasyncwriteleak.nim(59)  tasyncwriteleak
asyncdispatch.nim(1840)  waitFor
asyncdispatch.nim(1534)  poll
asyncdispatch.nim(1259)  runOnce
ioselectors_kqueue.nim(450) selectInto
selectors.nim(321)       verifySelectParams
Error: unhandled exception: Cannot select with a negative value, got -23 [ValueError]

The tasyncwriteleak file that I used will be included in a follow-up PR (and will likely be called something else).

@Araq

This comment has been minimized.

Copy link
Member

commented May 12, 2019

Can't we instead use pollTimeout: range[-1 .. high(int)]?

@dom96

This comment has been minimized.

Copy link
Member Author

commented May 14, 2019

We could, but that wouldn't solve the problem. Can we just merge this? It's an easy fix, whereas changing processTimers to return a range[-1 .. high(int)] would be relatively painful.

proc verifySelectParams(timeout: int) =
# Timeout of -1 means: wait forever
# Anything higher is the time to wait in miliseconds.
if timeout < -1:

This comment has been minimized.

Copy link
@Araq

Araq May 14, 2019

Member

use doAssert(timeout >= -1) instead, programming bugs are not exceptions to be handled.

This comment has been minimized.

Copy link
@dom96

dom96 May 15, 2019

Author Member

Then why do we even have a ValueError exception? Isn't that its purpose?

This comment has been minimized.

Copy link
@Araq

Araq May 15, 2019

Member

Regex parsing can fail because the user's input might not be a valid regex --> exception, programmer cannot pass the right value to timeout --> a bug, not an exception.

This comment has been minimized.

Copy link
@dom96

dom96 May 15, 2019

Author Member

Makes sense.

@Araq

This comment has been minimized.

Copy link
Member

commented May 14, 2019

We could, but that wouldn't solve the problem.

Why not?

@dom96

This comment has been minimized.

Copy link
Member Author

commented May 15, 2019

@Araq because that's not the variable that's negative? Making the result of processTimers a range would solve the problem, but that's not what you asked for :P

@Araq Araq merged commit d0b8724 into devel May 15, 2019

4 checks passed

continuous-integration/appveyor/branch AppVeyor build succeeded
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@Araq Araq deleted the fixes-negative-timeouts-in-async branch May 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.