Bug 36730 - (Bug 35428 follow-up) po files (sometimes) fail to update
Summary: (Bug 35428 follow-up) po files (sometimes) fail to update
Status: Pushed to oldstable
Alias: None
Product: Koha
Classification: Unclassified
Component: translate.koha-community.org (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low normal (vote)
Assignee: Janusz Kaczmarek
QA Contact: Testopia
URL:
Keywords: rel_23_05_candidate, rel_23_11_candidate
Depends on: 35428
Blocks:
  Show dependency treegraph
 
Reported: 2024-04-30 10:16 UTC by Janusz Kaczmarek
Modified: 2024-05-28 21:45 UTC (History)
4 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
24.05.00,23.11.06,23.05.12


Attachments
Bug 36730: (Bug 35428 follow-up) po files (sometimes) fail to update (1.68 KB, patch)
2024-04-30 10:22 UTC, Janusz Kaczmarek
Details | Diff | Splinter Review
Bug 36730: (Bug 35428 follow-up) po files (sometimes) fail to update (1.75 KB, patch)
2024-05-07 09:22 UTC, Jonathan Druart
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Janusz Kaczmarek 2024-04-30 10:16:49 UTC
Under some circumstances (e.g. non-standard disk latency) po files fail to be generated.  The output from the gulp po:update --lang xx-XX task is than like this:

[10:01:39] 'po_update_staff' errored after 6.41 s
[10:01:39] Error: ENOENT: no such file or directory, open '/tmp/koha-5WCc9s/Koha-staff-prog.pot'

This is due to the time dependencies inside the function flush (callback) (in the function xgettext) in gulpfile.js.  It happens that the /tmp/koha-NNNNNN folder gets deleted before the asynchronous callback function called by fs.readFile is completed.  The callback should copy the content of the .pot file from /tmp/koha- to its final destination, while, in parallel in fact, the folder inside /tmp is being removed.  This creates a race condition.

A patch proposal will follow.
Comment 1 Janusz Kaczmarek 2024-04-30 10:22:05 UTC
Created attachment 165836 [details] [review]
Bug 36730: (Bug 35428 follow-up) po files (sometimes) fail to update

Under some circumstances (e.g. non-standard disk latency) po files fail
to be generated.  The output from the gulp po:update --lang xx-XX task
is than like this:

[10:01:39] 'po_update_staff' errored after 6.41 s
[10:01:39] Error: ENOENT: no such file or directory, open '/tmp/koha-5WCc9s/Koha-staff-prog.pot'

This is due to the time dependencies inside the function flush (callback)
(in the function xgettext) in gulpfile.js.  It happens that the
/tmp/koha-NNNNNN folder gets deleted before the asynchronous callback
function called by fs.readFile is completed.  The callback should copy
the content of the .pot file from /tmp/koha- to its final destination,
while, in parallel in fact, the folder inside /tmp is being removed.
This creates a race condition.

Test plan:
==========
Hard to reproduce.  But the race condition found in the code should
be obvious.
Comment 2 Jonathan Druart 2024-05-07 09:22:32 UTC
Awesome, thanks!
Comment 3 Jonathan Druart 2024-05-07 09:22:53 UTC
Created attachment 166242 [details] [review]
Bug 36730: (Bug 35428 follow-up) po files (sometimes) fail to update

Under some circumstances (e.g. non-standard disk latency) po files fail
to be generated.  The output from the gulp po:update --lang xx-XX task
is than like this:

[10:01:39] 'po_update_staff' errored after 6.41 s
[10:01:39] Error: ENOENT: no such file or directory, open '/tmp/koha-5WCc9s/Koha-staff-prog.pot'

This is due to the time dependencies inside the function flush (callback)
(in the function xgettext) in gulpfile.js.  It happens that the
/tmp/koha-NNNNNN folder gets deleted before the asynchronous callback
function called by fs.readFile is completed.  The callback should copy
the content of the .pot file from /tmp/koha- to its final destination,
while, in parallel in fact, the folder inside /tmp is being removed.
This creates a race condition.

Test plan:
==========
Hard to reproduce.  But the race condition found in the code should
be obvious.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Comment 4 Katrin Fischer 2024-05-07 13:56:21 UTC
Pushed for 24.05!

Well done everyone, thank you!
Comment 5 Fridolin Somers 2024-05-24 14:14:58 UTC
Pushed to 23.11.x for 23.11.06
Comment 6 Lucas Gass 2024-05-28 21:45:20 UTC
Backported to 23.05.x for upcoming 23.05.12