RangerMauve / hyperswarm-web

Implementation of the hyperswarm API for use in web browsers
MIT License
102 stars 15 forks source link

hyperswarm-web crash #6

Closed ski closed 3 years ago

ski commented 3 years ago

The application crashes when close() is called on Hypercore. I get the following stack trace when close is called.

`Listening on ws://localhost:4977 -> Proxy available on ws://localhost:4977/proxy -> Signal available on ws://localhost:4977/signal /usr/lib/node_modules/hyperswarm-web/node_modules/hyperswarm-proxy/server.js:133 const boundPort = this.network.address().port ^

TypeError: Cannot read property 'address' of null at /usr/lib/node_modules/hyperswarm-web/node_modules/hyperswarm-proxy/server.js:133:38 at /usr/lib/node_modules/hyperswarm-web/node_modules/@hyperswarm/discovery/index.js:262:9 at Object.callback (/usr/lib/node_modules/hyperswarm-web/node_modules/dht-rpc/index.js:196:7) at IO._finish (/usr/lib/node_modules/hyperswarm-web/node_modules/dht-rpc/lib/io.js:157:9) at IO._onmessage (/usr/lib/node_modules/hyperswarm-web/node_modules/dht-rpc/lib/io.js:115:14) at UTP.emit (events.js:315:20) at UTP._onmessage (/usr/lib/node_modules/hyperswarm-web/node_modules/utp-native/index.js:199:8)`

I was just trying out the dat-sdk workshop code :

`const sdk = await window.datSDK(); const { Hypercore, close // <-- Make sure to call this when you're done } = sdk

    const core = Hypercore('alicecore', {
        valueEncoding: 'json',
        persist: false,
        storage: RAI 
    })

    await core.ready()
    const { key } = core

    console.log('Created core', { key })
    await core.append(JSON.stringify({
        name: 'Alice'
    }))
    console.log('Appended to core', core.length)
    const chunk = await core.get(0)        
    console.log('Loaded chunk', chunk)        
    const text = await core.get(0, { valueEncoding: 'utf8' })
    console.log('Loaded as text', text)
    await close() // <-- crashes hyperswarm-web here.`

What can I do to fix this issue? Thank you for your help. su./hail

tinchoz49 commented 3 years ago

Can you try the prev version 1.0.1?

tinchoz49 commented 3 years ago

@RangerMauve

I could reproduce the error here: https://github.com/RangerMauve/hyperswarm-web/pull/8

By destroying the hyperswarm-proxy it deletes the network property: https://github.com/RangerMauve/hyperswarm-proxy/blob/master/server.js#L226

but for some reasons (randomly) keep doing a ping here: https://github.com/RangerMauve/hyperswarm-proxy/blob/master/server.js#L126

A quick solution is to check for the network to be null.

RangerMauve commented 3 years ago

I'm super busy with contracts right now. Would anyone be up for submitting a PR based on @tinchoz49 's comments?

@ski would you feel comfortable giving it a shot?

RangerMauve commented 3 years ago

Huge thanks for the fix @tinchoz49 !

Released in 2.0.2 😁