Bug 261093 - [GTK] Race condition when reading the display number from Xvfb
Summary: [GTK] Race condition when reading the display number from Xvfb
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKitGTK (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Carlos Alberto Lopez Perez
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-09-03 17:33 PDT by Carlos Alberto Lopez Perez
Modified: 2023-09-20 02:19 PDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Carlos Alberto Lopez Perez 2023-09-03 17:33:25 PDT
The Xvfb driver for running layout tests with the GTK port starts the Xvfb server passing the parameter `-displayfd $fd` and then waits for Xvfb to write there the display number and closes the $fd pipe.

The problem is that the Xvfb program does not write the number in an atomic way.

It first writes the number itself and then it writes later the \n character.

See:

os/connection.c-void
os/connection.c-NotifyParentProcess(void)
os/connection.c-{
os/connection.c-#if !defined(WIN32)
os/connection.c:    if (displayfd >= 0) {
os/connection.c:        if (write(displayfd, display, strlen(display)) != strlen(display))
os/connection.c:            FatalError("Cannot write display number to fd %d\n", displayfd);
os/connection.c:        if (write(displayfd, "\n", 1) != 1)
os/connection.c:            FatalError("Cannot write display number to fd %d\n", displayfd);
os/connection.c:        close(displayfd);
os/connection.c:        displayfd = -1;
os/connection.c-    }


So it happens that we end in a race condition sometimes where we read the number from the first write and then we close the displayfd descriptor before Xvfb had wrote the \n character and that causes Xvfb to crash or to exit with an error.

Example:

Fatal server error:
(EE) Cannot write display number to fd 13
(EE)
Xvfb crashed [pid=18829]


This issue is causing sometimes unexpected crashes on the layout tests
Comment 1 Carlos Alberto Lopez Perez 2023-09-03 18:19:23 PDT
Pull request: https://github.com/WebKit/WebKit/pull/17393
Comment 2 EWS 2023-09-20 02:19:09 PDT
Committed 268189@main (413b2a19f079): <https://commits.webkit.org/268189@main>

Reviewed commits have been landed. Closing PR #17393 and removing active labels.