https://bugs.winehq.org/show_bug.cgi?id=47843
Bug ID: 47843 Summary: [Rockstar Game Launcher]Unable to download a game completly Product: Wine Version: 4.17 Hardware: x86-64 OS: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: bcrypt Assignee: wine-bugs@winehq.org Reporter: berillions@gmail.com Distribution: ---
Created attachment 65348 --> https://bugs.winehq.org/attachment.cgi?id=65348 Download stop after a while
Hello,
The new Rockstar Games Launcher can start to download a game but after a while, the downloading stop without reasons. In fact, the data value does not increase while the speed download change and is not at zero (see the screenshot) It seems that no more data are downloaded. Each time i close and launch the launcher, the download starts from zero.
In the output log, there are some lines about bcrypt algorythm not implemented : "002a:fixme:bcrypt:BCryptOpenAlgorithmProvider algorithm L"DH" not supported"
Or others lines like this (i don't know if it's important) : 0035:fixme:bcrypt:BCryptGenRandom ignoring selected algorithm
I add the +bcrypt log too.
https://bugs.winehq.org/show_bug.cgi?id=47843
Berillions berillions@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |berillions@gmail.com
--- Comment #1 from Berillions berillions@gmail.com --- Created attachment 65349 --> https://bugs.winehq.org/attachment.cgi?id=65349 Bcrypt trace during GTA SA downloading
https://bugs.winehq.org/show_bug.cgi?id=47843
Berillions berillions@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |hans@meelstraat.net
https://bugs.winehq.org/show_bug.cgi?id=47843
Brendan Shanks bshanks@codeweavers.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |bshanks@codeweavers.com
https://bugs.winehq.org/show_bug.cgi?id=47843
peuc@wanadoo.fr changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |peuc@wanadoo.fr
https://bugs.winehq.org/show_bug.cgi?id=47843
--- Comment #2 from Brendan Shanks bshanks@codeweavers.com --- I spent some time looking into this issue, it's not related to bcrypt but is actually a race condition caused by some shaky assumptions in the launcher service and how Wine implements the NT thread pool.
There's multiple processes involved: Launcher.exe is the GUI app. RockstarService.exe is the background service, it actually does the downloading and file I/O. They communicate through a named pipe ("\.\pipe\MTLService_Pipe") created by the service. They also write out separate log files: ProgramData/Rockstar Games/Launcher/service_log.txt for the service, and users/steamuser/My\ Documents/Rockstar\ Games/Launcher/launcher.log for the launcher. The service also logs mostly the same output with OutputDebugString().
The problem here is with the service, and it looks like this in service_log.txt (note that there's lots of "Last error" lines printed to this log that really aren't errors and don't matter):
[2019-10-21 15:09:11.255] [ 68] [ FD] Wrote to C:\Program Files\Rockstar Games\Grand Theft Auto San Andreas\models\gta3.img [2019-10-21 15:09:11.256] [ 68] [ 6D] Failed to write to pipe. [2019-10-21 15:09:11.256] [ 68] [ 6D] Last error: 996 (0x3e4): Overlapped I/O incomplete.
[2019-10-21 15:09:11.256] [ 68] [ 6D] Disconnected. [2019-10-21 15:09:11.257] [ 68] [ 6D] Destroying pipe...
The pipe then gets re-created, the whole service is restarted, and this is when the download stops. "Failed to write to pipe" is the error.
The service uses overlapped I/O to write to files, and before WriteFile() is called it uses RegisterWaitForSingleObject() to register a callback to fire when the overlapped I/O event is signaled/finished. The thread calls WriteFile() for the file, it returns quickly, and then WriteFile() is used to write a small message to the pipe (also overlapped). The file write callback just calls GetOverlappedResult(), if it succeeds it does some housekeeping (log messages, unregister wait, close handles) and also writes a small message to the pipe.
The problem is, the same OVERLAPPED structure is used for all writing to the pipe, regardless of what thread is doing the writing. There's also a callback registered for this overlapped event, it calls GetOverlappedResult() to confirm success. Eventually the pipe write from the original thread and from the file write callback happen at almost the same time. The pipe write callback calls GetOverlappedResult() on the shared OVERLAPPED which has been set to pending by the WriteFile() call happening simultaneously in the other thread, GetOverlappedResult() returns FALSE, it logs the "Failed to write to pipe" message, and starts tearing everything down.
Next question: why doesn't this break on Windows? The service calls RegisterWaitForSingleObject() with the WT_EXECUTEINWAITTHREAD flag. An understanding of the Windows thread pool is needed: Windows has a number of "wait threads" which each wait on multiple objects. When an object is signaled, normally the wait thread queues the callback to be executed by another thread, and then goes back to waiting. But when the WT_EXECUTEINWAITTHREAD flag is used, the wait thread itself calls the callback. This has the effect of serializing all callbacks being waited on by that wait thread. In this case, the launcher doesn't have many waits, so all the waits are handled by a single wait thread, and all callbacks are serialized. This behavior is certainly not guaranteed by Windows though, and shouldn't be depended upon.
In contrast, Wine's implementation spawns a new thread for each wait, and then calls the callback from that thread. The callbacks aren't serialized, and end up racing and causing this error.
Making Wine's thread pool implementation match Windows would be a big task. For now I tried a hacky solution of having each thread enter a process-wide critical section before calling the callback when WT_EXECUTEINWAITTHREAD is supplied, and it seems to solve the issue (I can download GTA:SA with no errors). I'll work on getting this upstream (at least into Proton). Also I've attached a test app which reproduces the problem.
https://bugs.winehq.org/show_bug.cgi?id=47843
Olivier F. R. Dierick o.dierick@piezo-forte.be changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |o.dierick@piezo-forte.be
--- Comment #3 from Olivier F. R. Dierick o.dierick@piezo-forte.be --- (In reply to Brendan Shanks from comment #2)
Also I've attached a test app which reproduces the problem.
Hello,
Thanks for the deep analysis.
It seems the attachment is not here.
Regards.
https://bugs.winehq.org/show_bug.cgi?id=47843
--- Comment #4 from Brendan Shanks bshanks@codeweavers.com --- Created attachment 65495 --> https://bugs.winehq.org/attachment.cgi?id=65495 test program reproducing problem
https://bugs.winehq.org/show_bug.cgi?id=47843
--- Comment #5 from Brendan Shanks bshanks@codeweavers.com --- Created attachment 65496 --> https://bugs.winehq.org/attachment.cgi?id=65496 Hack-y patch that should solve the issue
https://bugs.winehq.org/show_bug.cgi?id=47843
Alistair Leslie-Hughes leslie_alistair@hotmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Keywords| |patch
https://bugs.winehq.org/show_bug.cgi?id=47843
--- Comment #6 from Berillions berillions@gmail.com --- Great, the hack works for me too. Thanks Brendan. I hope someone in CW will implement this correctly :D
https://bugs.winehq.org/show_bug.cgi?id=47843
Hans Leidekker hans@meelstraat.net changed:
What |Removed |Added ---------------------------------------------------------------------------- Component|bcrypt |ntdll
https://bugs.winehq.org/show_bug.cgi?id=47843
maniikarabera@protonmail.ch changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |maniikarabera@protonmail.ch
https://bugs.winehq.org/show_bug.cgi?id=47843
Julian Rüger jr98@gmx.net changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |jr98@gmx.net
https://bugs.winehq.org/show_bug.cgi?id=47843
--- Comment #7 from Brendan Shanks bshanks@codeweavers.com --- This was fixed by Rémi Bernon in February with commit 26ee9134d5d75ee515ccf06987cd024b64e498aa
https://bugs.winehq.org/show_bug.cgi?id=47843
Gijs Vermeulen gijsvrm@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |FIXED Fixed by SHA1| |26ee9134d5d75ee515ccf06987c | |d024b64e498aa Status|UNCONFIRMED |RESOLVED Summary|[Rockstar Game |Rockstar Game Launcher is |Launcher]Unable to download |unable to download a game |a game completly |completely
--- Comment #8 from Gijs Vermeulen gijsvrm@gmail.com --- (In reply to Brendan Shanks from comment #7)
This was fixed by Rémi Bernon in February with commit 26ee9134d5d75ee515ccf06987cd024b64e498aa
Thanks for confirming Brendan, marking FIXED.
https://bugs.winehq.org/show_bug.cgi?id=47843
Alexandre Julliard julliard@winehq.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |CLOSED
--- Comment #9 from Alexandre Julliard julliard@winehq.org --- Closing bugs fixed in 6.23.