GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — dgram: call send callback asynchronously by yosuke-furukawa · Pull Request #1313 · nodejs/node

Conversation

@yosuke-furukawa

@yosuke-furukawa yosuke-furukawa commented Apr 1, 2015

Copy link
Copy Markdown
Member

According to this issue #486, every callbacks should be called asynchronously, But dgram.send callback is not called asynchronously.

We can not run full benchmark test. benchmark/net/dgram.js uses send callback recursively.
But send callback is not asynchronous, the recursive callback goes infinite loop.

If this fix is accepted, we could run full benchmark test on every release.

I think libuv changes the uv_udp_send API on this commit libuv/libuv@4189122.

So I just fixed callback asynchronously using setImmediate.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Fishrock123 Fishrock123 added the dgram Issues and PRs related to UDP and the dgram module. label Apr 1, 2015
@Fishrock123

Fishrock123 commented Apr 1, 2015

Copy link
Copy Markdown
Contributor

R=@bnoordhuis

(also, this may be semver-major, like process.send)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brendanashworth

brendanashworth commented Apr 3, 2015

Copy link
Copy Markdown
Contributor

I vote for bug fix, as it was once asynchronous and we just didn't notice the regression (?).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@yosuke-furukawa

yosuke-furukawa commented Apr 3, 2015

Copy link
Copy Markdown
Member Author

@brendanashworth I agree with that.
Node.js v0.10 works fine. But Node.js v0.11 doesn't.
IMO, this pull request is for bug fix. this change does not break compatibility, all existing tests are green.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@yosuke-furukawa yosuke-furukawa mentioned this pull request Apr 3, 2015
benchmark: disable dgram benchmark #1258
Closed
@brendanashworth

brendanashworth commented Apr 3, 2015

Copy link
Copy Markdown
Contributor

I feel like a fix for this should belong in libuv rather than io.js, it feels rather hacky, as I don't believe we do this for any other libuv bindings. Plus, it was a commit in libuv that caused this regression, thoughts?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@yosuke-furukawa

yosuke-furukawa commented Apr 3, 2015

Copy link
Copy Markdown
Member Author

"every callback should be asynchronous" is a rule for Node/io.js (#486 (comment)). libuv does not have the rule.

According to the libuv pull request joyent/libuv#1358, this change is to improve UDP request performance. So, this is not regression for libuv.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

trevnorris
trevnorris reviewed Apr 3, 2015
View reviewed changes
Comment thread lib/dgram.js

@trevnorris trevnorris Apr 3, 2015

Copy link
Copy Markdown
Contributor

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.

Hm. Would there still be the same problem if you used process.nextTick()?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@bnoordhuis bnoordhuis Apr 3, 2015

Copy link
Copy Markdown
Member

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 tried earlier today. setImmediate() works but process.nextTick() still hangs.

From some ad hoc testing I got the impression that the event loop is making some progress - i.e. it's not that dgram.send() is truly synchronous - but it's not making enough progress for the setTimeout timer in benchmark/net/dgram.js to fire.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@trevnorris

trevnorris commented Apr 3, 2015

Copy link
Copy Markdown
Contributor

Agreed this is a bug fix. The callback should have always been called asynchronously, and there's no API dependency requiring the order in which the callback is called.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bnoordhuis
bnoordhuis reviewed Apr 3, 2015
View reviewed changes
Comment thread test/parallel/test-dgram-send-callback-recursive.js Outdated

@bnoordhuis bnoordhuis Apr 3, 2015

Copy link
Copy Markdown
Member

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.

Sorry to be that guy but can you wrap this line at 80 columns?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bnoordhuis

bnoordhuis commented Apr 3, 2015

Copy link
Copy Markdown
Member

LGTM with style nits. The issue of why dgram behaves this way needs further investigation because I couldn't quite figure it out earlier today. What I observed is this:

  1. io.js uses uv_udp_send (not uv_udp_try_send) and that function always defers the callback, even if the write succeeds immediately.
  2. Still, the event loop doesn't make enough progress for the timer in the benchmark to fire.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis

bnoordhuis commented Apr 3, 2015

Copy link
Copy Markdown
Member

I think I had a moment of rubber duck debugging just there, I think I figured it out. :-)

uv_udp_send() pushes the request onto the completed queue when the write succeeds (which is nearly always.) The first time the callback fires:

  1. Libuv loops over the write requests in the completed queue.
  2. For every request, it hands it off to io.js
  3. io.js calls into JS land
  4. JS land calls uv_udp_send() again (dgram.send())
  5. The write succeed immediately and uv_udp_send() pushes the request onto the completed queue, the same queue it's currently iterating over.

I think this qualifies as a libuv bug. /cc @saghul

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis

bnoordhuis commented Apr 3, 2015

Copy link
Copy Markdown
Member

For the record, the patch below fixes (what is effectively) the infinite loop.

diff --git a/deps/uv/src/unix/udp.c b/deps/uv/src/unix/udp.c
index 941c0ae..177ad43 100644
--- a/deps/uv/src/unix/udp.c
+++ b/deps/uv/src/unix/udp.c
@@ -133,10 +133,8 @@ static void uv__udp_io(uv_loop_t* loop, uv__io_t* w, unsigned int revents) {
   if (revents & UV__POLLIN)
     uv__udp_recvmsg(handle);

-  if (revents & UV__POLLOUT) {
+  if (revents & UV__POLLOUT)
     uv__udp_sendmsg(handle);
-    uv__udp_run_completed(handle);
-  }
 }

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@saghul

saghul commented Apr 4, 2015

Copy link
Copy Markdown
Member

Yeah, I think it does qualify as a libuv bug. Can you open an issue for it?
(Sorry, I'm traveling and on mobile right now)
On Apr 3, 2015 23:11, "Ben Noordhuis" [email protected] wrote:

For the record, the patch below fixes (what is effectively) the infinite
loop.

diff --git a/deps/uv/src/unix/udp.c b/deps/uv/src/unix/udp.c
index 941c0ae..177ad43 100644--- a/deps/uv/src/unix/udp.c+++ b/deps/uv/src/unix/udp.c@@ -133,10 +133,8 @@ static void uv__udp_io(uv_loop_t* loop, uv__io_t* w, unsigned int revents) {
if (revents & UV__POLLIN)
uv__udp_recvmsg(handle);

  • if (revents & UV__POLLOUT) {+ if (revents & UV__POLLOUT)
    uv__udp_sendmsg(handle);- uv__udp_run_completed(handle);- }
    }

—
Reply to this email directly or view it on GitHub
#1313 (comment).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis bnoordhuis mentioned this pull request Apr 4, 2015
udp: callbacks are effectively synchronous libuv/libuv#301
Closed
@bnoordhuis

bnoordhuis commented Apr 4, 2015

Copy link
Copy Markdown
Member

Done: libuv/libuv#301

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@yosuke-furukawa
dgram: call send callback asynchronously
2b1ea20
@yosuke-furukawa

yosuke-furukawa commented Apr 4, 2015

Copy link
Copy Markdown
Member Author

Thank you @bnoordhuis !!

I fixed a test as you reviewed.

And I tried to apply the patch, but I got some Timeout errors on the io.js test.

=== release test-dgram-send-callback-buffer-length ===
Path: parallel/test-dgram-send-callback-buffer-length
/Users/yosuke/go/src/github.com/yosuke-furukawa/fork/io.js/test/parallel/test-dgram-send-callback-buffer-length.js:26
  throw new Error('Timeout');
        ^
Error: Timeout
    at null._onTimeout (/Users/yosuke/go/src/github.com/yosuke-furukawa/fork/io.js/test/parallel/test-dgram-send-callback-buffer-length.js:26:9)
    at Timer.listOnTimeout (timers.js:89:15)
Command: out/Release/iojs /Users/yosuke/go/src/github.com/yosuke-furukawa/fork/io.js/test/parallel/test-dgram-send-callback-buffer-length.js
=== release test-cluster-dgram-1 ===
Path: parallel/test-cluster-dgram-1
Command: out/Release/iojs /Users/yosuke/go/src/github.com/yosuke-furukawa/fork/io.js/test/parallel/test-cluster-dgram-1.js
--- TIMEOUT ---
=== release test-dgram-bytes-length ===
Path: parallel/test-dgram-bytes-length
Command: out/Release/iojs /Users/yosuke/go/src/github.com/yosuke-furukawa/fork/io.js/test/parallel/test-dgram-bytes-length.js
--- TIMEOUT ---
=== release test-dgram-exclusive-implicit-bind ===
Path: parallel/test-dgram-exclusive-implicit-bind
Command: out/Release/iojs /Users/yosuke/go/src/github.com/yosuke-furukawa/fork/io.js/test/parallel/test-dgram-exclusive-implicit-bind.js
--- TIMEOUT ---
=== release test-dgram-msgsize ===
Path: parallel/test-dgram-msgsize
Command: out/Release/iojs /Users/yosuke/go/src/github.com/yosuke-furukawa/fork/io.js/test/parallel/test-dgram-msgsize.js
--- TIMEOUT ---
=== release test-dgram-pingpong ===
Path: parallel/test-dgram-pingpong
server listening on 13048 undefined
Client sending to 13048, localhost PING
server listening on 13047 localhost
Client sending to 13047, localhost PING
server listening on 13046 localhost
Client sending to 13046, localhost PING
Command: out/Release/iojs /Users/yosuke/go/src/github.com/yosuke-furukawa/fork/io.js/test/parallel/test-dgram-pingpong.js
--- TIMEOUT ---
=== release test-dgram-send-callback-recursive ===
Path: parallel/test-dgram-send-callback-recursive
Command: out/Release/iojs /Users/yosuke/go/src/github.com/yosuke-furukawa/fork/io.js/test/parallel/test-dgram-send-callback-recursive.js
--- TIMEOUT ---
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis

bnoordhuis commented Apr 4, 2015

Copy link
Copy Markdown
Member

Sorry, I should have made clear that I don't consider that patch a proper fix, it's just to demonstrate that the uv__udp_run_completed() call causes the issue.

The PR LGTM but I suggest that in the commit log you explain what the issue is and that it's a temporary fix until libuv/libuv#301 is resolved.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@chrisdickinson chrisdickinson added the land-on-master label Apr 17, 2015
@brendanashworth

brendanashworth commented May 10, 2015

Copy link
Copy Markdown
Contributor

@yosuke-furukawa ping on a merge

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@yosuke-furukawa

yosuke-furukawa commented May 10, 2015

Copy link
Copy Markdown
Member Author

oops, I will merge it soon.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

yosuke-furukawa added a commit that referenced this pull request May 10, 2015
@yosuke-furukawa
dgram: call send callback asynchronously
18d457b
dgram#send callback was changed synchronously.
The PR-URL is here joyent/libuv#1358

This commit is temporary fix until libuv issue is resolved.
libuv/libuv#301

PR-URL: #1313
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
@yosuke-furukawa

yosuke-furukawa commented May 10, 2015

Copy link
Copy Markdown
Member Author

Landed on 18d457b
Thank you for review.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@yosuke-furukawa yosuke-furukawa closed this May 10, 2015
@evanlucas evanlucas mentioned this pull request May 11, 2015
Random test failures in test/parallel/test-dgram-send-callback-recursive.js #1675
Closed
@Fishrock123

Fishrock123 commented May 11, 2015

Copy link
Copy Markdown
Contributor

This test case fails on our CI. Please make sure to run things like this on the CI before landing. :)

https://jenkins-iojs.nodesource.com/view/iojs/job/iojs+any-pr+multi/657/nodes=osx1010/tapTestReport/test.tap-153/

https://jenkins-iojs.nodesource.com/view/iojs/job/iojs+any-pr+multi/657/nodes=win2012r2/tapTestReport/test.tap-153/

https://jenkins-iojs.nodesource.com/view/iojs/job/iojs+any-pr+multi/657/nodes=win2008r2/tapTestReport/test.tap-153/

not ok 153 - test-dgram-send-callback-recursive.js
# c:\workspace\iojs+any-pr+multi\nodes\win2012r2\test\parallel\test-dgram-send-callback-recursive.js:14
# throw new Error('infinite loop detected');
# ^
# Error: infinite loop detected
# at SendWrap.onsend [as callback] (c:\workspace\iojs+any-pr+multi\nodes\win2012r2\test\parallel\test-dgram-send-callback-recursive.js:14:11)
# at Immediate._onImmediate (dgram.js:342:10)
# at processImmediate [as _immediateCallback] (timers.js:368:17)
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Fishrock123 Fishrock123 mentioned this pull request May 12, 2015
Release proposal: v2.0.2 #1679
Merged
Fishrock123 added a commit to Fishrock123/node that referenced this pull request May 15, 2015
@Fishrock123
2015-05-15 io.js v2.0.2 Release
3e7a143
PR-URL: nodejs#1679

Notable Changes:

* win,node-gyp: the delay-load hook for windows addons has now been
correctly enabled by default, it had wrongly defaulted to off in the
release version of 2.0.0 (Bert Belder) nodejs#1433
* os: tmpdir()'s trailing slash stripping has been refined to fix an
issue when the temp directory is at '/'. Also considers which slash is
used by the operating system. (cjihrig) nodejs#1673
* tls: default ciphers have been updated to use gcm and aes128 (Mike
MacCana) nodejs#1660
* build: v8 snapshots have been re-enabled by default as suggested by
the v8 team, since prior security issues have been resolved. This
should give some perf improvements to both startup and vm context
creation. (Trevor Norris) nodejs#1663
* src: fixed preload modules not working when other flags were used
before --require (Yosuke Furukawa) nodejs#1694
* dgram: fixed send()'s callback not being asynchronous (Yosuke
Furukawa) nodejs#1313
* readline: emitKeys now keeps buffering data until it has enough to
parse. This fixes an issue with parsing split escapes. (Alex Kocharin)
* cluster: works now properly emit 'disconnect' to cluser.worker (Oleg
Elifantiev) nodejs#1386
events: uncaught errors now provide some context (Evan Lucas) nodejs#1654
Fishrock123 pushed a commit to Fishrock123/node that referenced this pull request May 19, 2015
@yosuke-furukawa @Fishrock123
dgram: call send callback asynchronously
e05afd7
dgram#send callback was changed synchronously.
The PR-URL is here joyent/libuv#1358

This commit is temporary fix until libuv issue is resolved.
libuv/libuv#301

PR-URL: nodejs#1313
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
saghul added a commit to saghul/node that referenced this pull request Jun 3, 2015
@saghul
dgram: partially revert 18d457b
7456692
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 that referenced this pull request Jun 3, 2015
@saghul @bnoordhuis
dgram: partially revert 18d457b
b5cd2f0
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 <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
nodejs-github-bot pushed a commit that referenced this pull request Nov 14, 2026
@TrevorBurnham
doc: explain how sqlite binds numbers and BigInts
b5e3a61
A JavaScript number is always bound with sqlite3_bind_double(), so it is
written as REAL even when it has no fractional part. A BigInt is bound
with sqlite3_bind_int64() and is the way to write an INTEGER. The type
conversion table listed number under both INTEGER and REAL without
saying which applies when, so the rule had to be discovered by
experiment.

Column type affinity hides this most of the time, which is why the cases
it does not cover are surprising. Comparing against a TEXT column is the
worst of them: the number 3 compares as '3.0' and silently fails to
match a stored '3', with no error to point at the cause. Document the
rule, the reason for it, and that case, and remove number from the
table's INTEGER row. Point the virtual table section's link at the new
text.

better-sqlite3 binds numbers the same way and has fielded the same
question repeatedly (WiseLibs/better-sqlite3#165, #627, #897, #1144,
#1313), each time closed as working as intended.

Fixes: #63826
Refs: WiseLibs/better-sqlite3#627
Assisted-by: Claude Opus 5.5
Signed-off-by: Trevor Burnham <[email protected]>
PR-URL: #67424
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Guilherme Araújo <[email protected]>
aduh95 pushed a commit that referenced this pull request Nov 16, 2026
@TrevorBurnham @aduh95
doc: explain how sqlite binds numbers and BigInts
a23a18b
A JavaScript number is always bound with sqlite3_bind_double(), so it is
written as REAL even when it has no fractional part. A BigInt is bound
with sqlite3_bind_int64() and is the way to write an INTEGER. The type
conversion table listed number under both INTEGER and REAL without
saying which applies when, so the rule had to be discovered by
experiment.

Column type affinity hides this most of the time, which is why the cases
it does not cover are surprising. Comparing against a TEXT column is the
worst of them: the number 3 compares as '3.0' and silently fails to
match a stored '3', with no error to point at the cause. Document the
rule, the reason for it, and that case, and remove number from the
table's INTEGER row. Point the virtual table section's link at the new
text.

better-sqlite3 binds numbers the same way and has fielded the same
question repeatedly (WiseLibs/better-sqlite3#165, #627, #897, #1144,
#1313), each time closed as working as intended.

Fixes: #63826
Refs: WiseLibs/better-sqlite3#627
Assisted-by: Claude Opus 5.5
Signed-off-by: Trevor Burnham <[email protected]>
PR-URL: #67424
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Guilherme Araújo <[email protected]>
aduh95 pushed a commit that referenced this pull request Nov 17, 2026
@TrevorBurnham @aduh95
doc: explain how sqlite binds numbers and BigInts
1151d51
A JavaScript number is always bound with sqlite3_bind_double(), so it is
written as REAL even when it has no fractional part. A BigInt is bound
with sqlite3_bind_int64() and is the way to write an INTEGER. The type
conversion table listed number under both INTEGER and REAL without
saying which applies when, so the rule had to be discovered by
experiment.

Column type affinity hides this most of the time, which is why the cases
it does not cover are surprising. Comparing against a TEXT column is the
worst of them: the number 3 compares as '3.0' and silently fails to
match a stored '3', with no error to point at the cause. Document the
rule, the reason for it, and that case, and remove number from the
table's INTEGER row. Point the virtual table section's link at the new
text.

better-sqlite3 binds numbers the same way and has fielded the same
question repeatedly (WiseLibs/better-sqlite3#165, #627, #897, #1144,
#1313), each time closed as working as intended.

Fixes: #63826
Refs: WiseLibs/better-sqlite3#627
Assisted-by: Claude Opus 5.5
Signed-off-by: Trevor Burnham <[email protected]>
PR-URL: #67424
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Guilherme Araújo <[email protected]>
gabylb pushed a commit to gabylb/node that referenced this pull request Nov 27, 2026
@TrevorBurnham @gabylb
doc: explain how sqlite binds numbers and BigInts
8ce206e
A JavaScript number is always bound with sqlite3_bind_double(), so it is
written as REAL even when it has no fractional part. A BigInt is bound
with sqlite3_bind_int64() and is the way to write an INTEGER. The type
conversion table listed number under both INTEGER and REAL without
saying which applies when, so the rule had to be discovered by
experiment.

Column type affinity hides this most of the time, which is why the cases
it does not cover are surprising. Comparing against a TEXT column is the
worst of them: the number 3 compares as '3.0' and silently fails to
match a stored '3', with no error to point at the cause. Document the
rule, the reason for it, and that case, and remove number from the
table's INTEGER row. Point the virtual table section's link at the new
text.

better-sqlite3 binds numbers the same way and has fielded the same
question repeatedly (WiseLibs/better-sqlite3#165, nodejs#627, nodejs#897, nodejs#1144,
nodejs#1313), each time closed as working as intended.

Fixes: nodejs#63826
Refs: WiseLibs/better-sqlite3#627
Assisted-by: Claude Opus 5.5
Signed-off-by: Trevor Burnham <[email protected]>
PR-URL: nodejs#67424
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Guilherme Araújo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

dgram Issues and PRs related to UDP and the dgram module.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@yosuke-furukawa @Fishrock123 @brendanashworth @trevnorris @bnoordhuis @saghul @chrisdickinson
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.