Skip to content

Make sure UDP send callbacks are always fired asynchronously - #371

Merged
saghul merged 2 commits into
libuv:v1.xfrom
saghul:udp_async
May 28, 2015
Merged

saghul merged 2 commits into
libuv:v1.xfrom
saghul:udp_async

Conversation

@saghul

@saghul saghul commented May 27, 2015

Copy link
Copy Markdown
Member

R=@bnoordhuis

Fixes: #301

@saghul

saghul commented May 27, 2015

Copy link
Copy Markdown
Member Author

Well, fuck.I'm afraid the change to uv__run_pending has some interesting side effects, as in 40 failing tests or something :-(

@saghul

saghul commented May 27, 2015

Copy link
Copy Markdown
Member Author

The problem seems to be the following:

  • The first time around, uv_udp_send sends immediately, so uv__udp_sendmsg is called and the io handle is set as pending with uv__io_feed, in order to run the callback on the next tick.
  • On the next tick, while in uv__run_pending, we call uv_udp_send again, and because we get UV__POLLOUT, we also try to write the queued send requests, and we succeed! so we call uv__io_feed again, to call its callback.
  • Since we're ietarting the pending queue, and uv__io_feed adds the handle to that very same queue, we enter an infinite loop.

I'll keep digging...

@saghul

saghul commented May 27, 2015

Copy link
Copy Markdown
Member Author

Solved it! All tests pass, it was a fuckup in using QUEUE_FOREACH. @bnoordhuis can you PTAL?

@bnoordhuis

Copy link
Copy Markdown
Member

LGTM

@saghul
saghul merged commit 1816dbc into libuv:v1.x May 28, 2015
@saghul

saghul commented May 28, 2015

Copy link
Copy Markdown
Member Author

Thanks Ben! Adjusted the comment and landed.

saghul added 2 commits May 28, 2015 11:05
If any of the callbacks called in uv__run_pending calls
uv__io_feed we enter an infinite loop, because we add the handle to the
same queue we are iterating over.

Refs: libuv#301
PR-URL: libuv#371
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Fixes: libuv#301
PR-URL: libuv#371
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
saghul added a commit to saghul/node that referenced this pull request Jun 3, 2015
Revert "dgram: call send callback asynchronously" partially, since the
fix is now done in libuv.

Refs: nodejs#1313
Refs: libuv/libuv#371
bnoordhuis pushed a commit to nodejs/node that referenced this pull request Jun 3, 2015
Revert "dgram: call send callback asynchronously" partially, since the
fix is now done in libuv.

Refs: #1313
Refs: libuv/libuv#371
PR-URL: #1889
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
guworks pushed a commit to guworks/libuv that referenced this pull request Jul 9, 2015
If any of the callbacks called in uv__run_pending calls
uv__io_feed we enter an infinite loop, because we add the handle to the
same queue we are iterating over.

Refs: libuv#301
PR-URL: libuv#371
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
guworks pushed a commit to guworks/libuv that referenced this pull request Jul 9, 2015
Fixes: libuv#301
PR-URL: libuv#371
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
skomski pushed a commit to skomski/libuv that referenced this pull request Aug 5, 2015
If any of the callbacks called in uv__run_pending calls
uv__io_feed we enter an infinite loop, because we add the handle to the
same queue we are iterating over.

Refs: libuv#301
PR-URL: libuv#371
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
skomski pushed a commit to skomski/libuv that referenced this pull request Aug 5, 2015
Fixes: libuv#301
PR-URL: libuv#371
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
skomski pushed a commit to skomski/libuv that referenced this pull request Aug 5, 2015
If any of the callbacks called in uv__run_pending calls
uv__io_feed we enter an infinite loop, because we add the handle to the
same queue we are iterating over.

Refs: libuv#301
PR-URL: libuv#371
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
skomski pushed a commit to skomski/libuv that referenced this pull request Aug 5, 2015
Fixes: libuv#301
PR-URL: libuv#371
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

udp: callbacks are effectively synchronous

2 participants

Sponsor
SponsoredKunjungi sekarang
Promo