-
Notifications
You must be signed in to change notification settings - Fork 7.3k
dgram.send() callback can be executed either sync or async #1456
Comments
As a broader question, is there a general convention in Node for whether callbacks are sync or async? I had generally assumed they were always async, and all the APIs I can think of that I used other than |
Looks like maybe a similar issue as to issue 1164 (#1164), and that would imply that sometimes a non-IP address value would also cause a sync callback. |
I agree. I think dgram's methods should invoke callback asynchronously. |
Please review 09f753f. |
@koichik: can we hold this off for a few days? I'm integrating libuv UDP support into node and this patch would mess up my work. libuv always executes the callback asynchronously, by the way. |
Awesome! I throw out this patch. |
Probably still need the addMembership()/removeMembership() callbacks from the patch, though, |
There's no (good) way to tell if the callback you are passing into
dgram.send()
will be executed synchronously and recursively, or whether it'll be called async by the main loop. If you are expecting it to be deferred (as I was), you could easily hit a stack overflow. Consider the code:With most other APIs in Node, the callback is executed in the main loop. With
dgram.send()
it's only async if a DNS lookup is required. Otherwise, it's inline and synchronous. In the code above, as long asaddress
is an IP address and the buffer is large enough, it will crash with a stack overflow.My buddy Havoc had a good blog post on this very topic a few days ago: http://blog.ometer.com/2011/07/24/callbacks-synchronous-and-asynchronous/ :)
The text was updated successfully, but these errors were encountered: