EliasKotlyar / Xiaomi-Dafang-Hacks

4.19k stars 1k forks source link

snapshot race condition on detectionOn.sh #1718

Closed jayekub closed 3 years ago

jayekub commented 3 years ago

i just enabled samba snapshots but the tempfile was getting cleaned up before smbclient ran. detectionOn.sh:204 calls the send_snapshot function in the background, but then the individual snapshot conditions are wrapped in backgrounded subshells as well. the result is that the wait loop starting at detectionOn.sh:360 doesn't wait for the sub-sub-processes and the tempfile is removed too soon.

as a quick fix i removed the & at the end of line 204 so the send_snapshot runs in the main shell. i'll make a pull request when i get around to it, but i've got a week old newborn at home now so it's likely that won't be for a while.

Model: | Wyzecam V2 Firmware date: | 2021-03-23T12:11:43Z Firmware Branch: | master Firmware Commit: | 116c1ad ( null commits behind Github)

tim-devel commented 3 years ago

I'm not sure removing the & is a long term fix as this would delay the start of recording a motion video. I think the for loop at 362 is supposed to wait for all jobs to end before the temp file is deleted

jayekub commented 3 years ago

Ah good point.

As far as I can tell that wait loop isn’t currently working as intended...

Nazim-ua commented 3 years ago

I added a checking to complete the background work in the send_snapshot function. Now the send_snapshot function will not complete its work until all of its subtasks are completed. After this change, sending snapshots worked correctly. I made a pull request, please review it.

tim-devel commented 3 years ago

Thanks @Nazim-ua but I can't see your pull request??

Nazim-ua commented 3 years ago

Sorry this is my first pull request, it didn't work the first time)) Check it now.

jmtatsch commented 3 years ago

Was fixed in 3935ddfd50ceff4017c1edfd0428de05eb0acc35 i think.

jayekub commented 3 years ago

Thanks!!

On Thu, Apr 29, 2021 at 8:19 AM jmtatsch @.***> wrote:

Closed #1718 https://github.com/EliasKotlyar/Xiaomi-Dafang-Hacks/issues/1718.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/EliasKotlyar/Xiaomi-Dafang-Hacks/issues/1718#event-4663473842, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEBFMYH44QXUBKC4BAOEMDTLF2HPANCNFSM42HYB6XQ .