samemory / homebridge-eufy-security

Work in progress
Apache License 2.0
97 stars 14 forks source link

[Bug]: BETA - NamePipeStream assumes it can write to current directory #308

Closed jak closed 2 years ago

jak commented 2 years ago

What happened?

In the current beta branch, NamePipeStream assumes it can write to the current directory.

In my dockerised setup, it cannot. My suggestion would be to use /run or /var/run, or use a library to determine a suitable location for writing temporary files/sockets.

Device Type

Doorbell (Supported)

Plugin Version

beta (Best Effort)

HomeBridge Version

v1.3.x (Supported)

NodeJS Version

v16 (Supported)

Operating System

Docker

Relevant log output

[12/28/2021, 12:52:50 AM] [EufySecurity-1.1.1-beta.4] DEBUG: Doorbell Video stream requested: 1280 x 720, 30 fps, 299 kbps true
[12/28/2021, 12:52:50 AM] [EufySecurity-1.1.1-beta.4] INFO:  Doorbell Starting video stream: 1280 x 720, 30 fps, 299 kbps (AAC-eld)
[12/28/2021, 12:52:50 AM] [EufySecurity-1.1.1-beta.4] DEBUG: Doorbell_video Stream command: ffmpeg -use_wallclock_as_timestamps 1 -r 15 -i unix:./2.sock -an -sn -dn -codec:v libx264 -pix_fmt yuv420p -color_range mpeg -r 30 -preset ultrafast -tune zerolatency -filter:v scale='min(1280,iw)':'min(720,ih)':force_original_aspect_ratio=decrease,scale='trunc(iw/2)*2:trunc(ih/2)*2' -b:v 299k -payload_type 99 -ssrc 1602065 -f rtp -srtp_out_suite AES_CM_128_HMAC_SHA1_80 -srtp_out_params xxx srtp://1.9.2.4:52678?rtcpport=52678&pkt_size=1316 -loglevel level+verbose -progress pipe:1
[12/28/2021, 12:52:50 AM] Error: listen EACCES: permission denied ./2.sock
    at Server.setupListenHandle [as _listen2] (node:net:1317:21)
    at listenInCluster (node:net:1382:12)
    at Server.listen (node:net:1480:5)
    at new NamePipeStream (/homebridge/node_modules/homebridge-eufy-security/src/accessories/UniversalStream.ts:35:21)
    at StreamInput (/homebridge/node_modules/homebridge-eufy-security/src/accessories/UniversalStream.ts:44:12)
    at StreamingDelegate.startStream (/homebridge/node_modules/homebridge-eufy-security/src/accessories/streamingDelegate.ts:384:41)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
github-actions[bot] commented 2 years ago

Did you check this Common Issues pages ?

lenoxys commented 2 years ago

We don't support Docker at this time

jak commented 2 years ago

This isn't Docker specific

lenoxys commented 2 years ago

This is because Docker implies NAT and the stream is generated with dynamic port which can be guessed

jak commented 2 years ago

This bug is about file system permissions for temporary files - it is not related to networking at all.

schliemann commented 2 years ago

@jak Can you propose a fix?

C4ptainMeow commented 2 years ago

I have the Same Probleme.

schliemann commented 2 years ago

I will be looking at changing the way we livestream in the beta next week. Might solve this issue.

alternativ commented 2 years ago

@schliemann, @lenoxys, this has to do with the setup of directories in the docker image. The following code: const osType = os_1.default.type(); if (osType === 'Windows_NT') { path = '\\\\.\\pipe\\stream' + (++counter); this.url = path; }else { path = './' + (++counter) + '.sock' this.url = 'unix:' + path } tries to create a 1..n.sock file in the directory: homebridge/node_modules/homebridge-eufy-security/dist/accessories (not writeable).

I changed that to the following code (and created the appropriate folder in the volume mounted to the docker container):

const osType = os_1.default.type(); if (osType === 'Windows_NT') { path = '\\\\.\\pipe\\stream' + (++counter); this.url = path; } else { path = '/homebridge/socket/' + (++counter) + '.sock'; this.url = 'unix:' + path; this.log.error('current_path', path); this.log.error('parent_dir',__dirname); }

Resulting in a working stream (that drops after a few seconds but I think that is a known issue, at least I saw that on my RP3).

lenoxys commented 2 years ago

hey @alternativ thanks for chasing this. I've implemented a more official way using the path provided by Homebridge but can't test it.

Could you test it (beta.26) ?

alternativ commented 2 years ago

@lenoxys, tested and stream works (but drops after ~10 seconds). Error in logs remaining [2/21/2022, 5:53:30 PM] [homebridge-eufy-security] Doorbell Error occurred closing socket: Error [ERR_SOCKET_DGRAM_NOT_RUNNING]: Not running

njuart commented 2 years ago

@lenoxys, tested and stream works (but drops after ~10 seconds).

Error in logs remaining [2/21/2022, 5:53:30 PM] [homebridge-eufy-security] Doorbell Error occurred closing socket: Error [ERR_SOCKET_DGRAM_NOT_RUNNING]: Not running

Try to enable debug mode in plugin, with it on, it won't crash. I've already reported about the issue, but looks like there is no much progress with it.

alternativ commented 2 years ago

@lenoxys, tested and stream works (but drops after ~10 seconds). Error in logs remaining [2/21/2022, 5:53:30 PM] [homebridge-eufy-security] Doorbell Error occurred closing socket: Error [ERR_SOCKET_DGRAM_NOT_RUNNING]: Not running

Try to enable debug mode in plugin, with it on, it won't crash. I've already reported about the issue, but looks like there is no much progress with it.

This works as expected. @lenoxys, issue can be closed.

lenoxys commented 2 years ago

thanks for your feedback.

For the issue on stream been stopped earlier when debug disable please use this issue thread #356