sagemathinc / websocketfs

WebSocketFS: it's like sshfs, but over a WebSocket and implemented in Typescript
MIT License
13 stars 3 forks source link

support nodejs version 20.x (only a problem for testing with client/server in the same process) #1

Open williamstein opened 1 year ago

williamstein commented 1 year ago

The following is a minimal reproducible example to show how this doesn't work with node 20 (but does with node 18 and 16).

~/websocketfs$ node
Welcome to Node.js v20.5.1.
Type ".help" for more information.
>  z = await require('.').bind(process.env.HOME,'/tmp/mnt'); null
null
> await require('fs/promises').writeFile('/tmp/mnt/a','foo'); (await require('fs/promises').readFile('/tmp/mnt/a')).toString()
> Uncaught [Error: ETIMEDOUT: connection timed out, open '/tmp/mnt/a'] {
  errno: -110,
  code: 'ETIMEDOUT',
  syscall: 'open',
  path: '/tmp/mnt/a'
williamstein commented 1 year ago

This deadlock only happens when the client and server are running in the same process.

williamstein commented 1 year ago
require('fs').open('/tmp/mnt2/a',(a,b)=>{console.log('FIRST', b); require('fs').open('/tmp/mnt2/a',(a,b)=>console.log("SECOND",b));})

I think the problem is entirely due to having the client and the server in the same process. If they are run in separate processes, things are fine. For any real use of websocketfs, they are in a separate process. For testing it is very convenient to have the client and server in the same process.

williamstein commented 1 year ago

Note that node-fuse is a C module that is being directly linked, and that's very likely what leads to the locks.

I also find that using websocketfs combined with a separate websocket for something else in the same process docker container leads to a lock.

Workaround: put websocketfs in its own process.

It might be that the fix for this particular issue is to use a webworker in nodejs. I wonder if that works?