holepunchto / hyperswarm

A distributed networking stack for connecting peers.
https://docs.holepunch.to
MIT License
1.04k stars 84 forks source link

Errors from utp-native #59

Closed heapwolf closed 4 years ago

heapwolf commented 4 years ago

Has anyone seen this error with utp-native?

node[51393]: ../src/node_buffer.cc:220:char *node::Buffer::Data(Local<v8::Value>): Assertion `val->IsArrayBufferView()' failed.                         
1: 0x1011c2f75 node::Abort() (.cold.1) [/usr/local/bin/node] 
2: 0x10009cfe9 node::Abort() [/usr/local/bin/node]                         
3: 0x10009ce51 node::Assert(node::AssertionInfo const&) [/usr/local/bin/node]                                                                          
4: 0x100079ce9 node::Buffer::Data(v8::Local<v8::Value>) [/usr/local/bin/node]                                                                          
5: 0x100075683 napi_get_buffer_info [/usr/local/bin/node]                  
6: 0x1059da6b0 utp_napi_bind(napi_env__*, napi_callback_info__*) [/Users/paolofragomeni/projects/optoolco/x/node_modules/utp-native/prebuilds/darwin-x64/node.napi.node]                                                    
7: 0x100953c36 uv__udp_io [/usr/local/bin/node]                            
8: 0x10095764f uv__io_poll [/usr/local/bin/node]                           
9: 0x1009448f1 uv_run [/usr/local/bin/node]                                
10: 0x1000da345 node::NodeMainInstance::Run() [/usr/local/bin/node]         
11: 0x100072e63 node::Start(int, char**) [/usr/local/bin/node]              
12: 0x7fff6a6ab2e5 start [/usr/lib/system/libdyld.dylib]                    
[1]    51393 abort      INST=1 ./bin/x.js
mafintosh commented 4 years ago

From using latest swarm? Haven’t seen that no

heapwolf commented 4 years ago

yeah, latest swarm

mafintosh commented 4 years ago

Do you have an example or something like that to help me debug?

heapwolf commented 4 years ago

im on node 12.16.2. @indutny was also able to confirm that he has seen this before but was not able to reproduce reliably.

heapwolf commented 4 years ago
  1. Clone this repo, npm install, and then in one terminal window run INST=0 ./bin/peerchan.js, and in a second, INST=1 ./bin/peerchan.js.

  2. Click on the blue line at the bottom of the window to focus if its not already focused. That's where you enter text. Type /id user1 in the first window, and /id user2 in the second.

  3. Type /r in the second window to request an invite to the chat in the fist window.

  4. Copy to clipboard is a little squirrely, so you may need to use your mouse to select the invite text. But paste /a user2 8fbc1... into the first window.

  5. Chat with yourself for a bit and at some point it should crash...

mafintosh commented 4 years ago

Amazing, thanks @heapwolf - will try to repro today. Is this crashing for you on mac or linux?

heapwolf commented 4 years ago

Its crashing on both. I feel like ive narrowed it down (possibly?) when I issue the command /r the copy button wasn't working, so I tried it again, this would have caused to invites to be waited on... hmm, still investigating it, but if im careful not to do that it's not crashing.

mafintosh commented 4 years ago

Good info, I didn’t get to it today but first on the list tmw

indutny commented 4 years ago

I wonder if _onclose() can be called in utp-native before .bind() somehow?

mafintosh commented 4 years ago

@heapwolf can repro

mafintosh commented 4 years ago

I figured it out! Our error logic forwarding logic had a mistake, and @heapwolf's program is shallowing uncaughts.

@heapwolf this is the uncaught that leads to the abort

TypeError: Cannot destructure property 'trusteeName' of 'currentInvite' as it is undefined.
    at Button.<anonymous> (/Users/maf/dev/node_modules/utp-native/foo/peerchan/src/views/invite.js:47:22)
    at Button.EventEmitter._emit (/Users/maf/dev/node_modules/utp-native/foo/peerchan/node_modules/neo-blessed/lib/events.js:98:20)
    at Button.EventEmitter.emit (/Users/maf/dev/node_modules/utp-native/foo/peerchan/node_modules/neo-blessed/lib/events.js:117:12)
    at Program.<anonymous> (/Users/maf/dev/node_modules/utp-native/foo/peerchan/node_modules/neo-blessed/lib/widgets/screen.js:508:34)
    at Program.emit (events.js:310:20)
    at Program._bindMouse (/Users/maf/dev/node_modules/utp-native/foo/peerchan/node_modules/neo-blessed/lib/program.js:703:10)
    at Program.<anonymous> (/Users/maf/dev/node_modules/utp-native/foo/peerchan/node_modules/neo-blessed/lib/program.js:566:10)
    at Program.emit (events.js:310:20)
    at /Users/maf/dev/node_modules/utp-native/foo/peerchan/node_modules/neo-blessed/lib/program.js:418:15
    at Array.forEach (<anonymous>)

(It obvs shouldn't abort Node.js, i'll fix that part)

mafintosh commented 4 years ago

For reference here is a simple repro case

const utp = require('utp-native')

const s= utp()

s.bind(0)
s.on('message', function () {
  throw new Error('crash')
})

setInterval(function () {
  const size = 4096
  s.send(Buffer.alloc(size), 0, size, s.address().port, '127.0.0.1')
}, 100)

process.on('uncaughtException', function (err) {
  console.log(err)
})

Current utp-native expects you to crash on uncaughts which is why I haven't seen this before I guess. Submitting a patch shortly

mafintosh commented 4 years ago

utp fix: https://github.com/mafintosh/utp-native/commit/0c7174904db3b8c804afa250c9ba6263077bdc25

will make a new release tmw

indutny commented 4 years ago

Fantastic resolution time. Thank you, @mafintosh !

mafintosh commented 4 years ago

Fix released with prebuilds

mafintosh commented 4 years ago

(gonna close this, @heapwolf feel free to comment if it works)

heapwolf commented 4 years ago

@mafintosh right on! you rock! 🎉