Skip to content

Conversation

jakepetroules
Copy link
Collaborator

@jakepetroules jakepetroules commented Jul 25, 2025

This hang occurred only in CI environments and only on Linux. Here's the sequence of events:

  • Test terminates swbuild using SIGKILL
  • OS reparents SWBBuildService (a subprocess of swbuild) to launchd (Darwin) / init (others)
  • OS closes the file descriptors for the I/O pipes swbuild has connected to SWBBuildService
  • SWBBuildService's read() loop indicates EOF due to the broken pipe
  • SWBBuildService causes itself to exit

At this point, the getpgid loop should return ERSCH and terminate the test. However, SWBBuildService is sticking around as a zombie for an extended period of time without init reaping the pid, causing getpgid to never hit the termination state. This causes the test to hang indefinitely.

To fix this, there are two aspects:

  • A timeout is added around the termination monitoring loop that forces the exit promise to be fulfilled with an error if a 30-second interval elapses without the process exiting
  • We switch from using a getpgid loop to using a waitid loop, where the terminal state is that the process has exited... we don't care if the zombie hasn't been collected by init, only that it's not in a running state

This fixes the hang for both the Jenkins based CI as well as GitHub actions, and also insulates us against future hangs by ensuring the test will terminate with a timeout error instead of hanging indefinitely, so that we at least know which test is the problem.

@jakepetroules
Copy link
Collaborator Author

@swift-ci test

@jakepetroules jakepetroules force-pushed the eng/PR-hanging-tests branch from 8677081 to 8a8a566 Compare July 25, 2025 06:29
@jakepetroules
Copy link
Collaborator Author

@swift-ci test

@jakepetroules jakepetroules force-pushed the eng/PR-hanging-tests branch from 8a8a566 to d59ebe0 Compare July 25, 2025 08:42
@jakepetroules
Copy link
Collaborator Author

@swift-ci test

@jakepetroules jakepetroules force-pushed the eng/PR-hanging-tests branch 12 times, most recently from 48448c2 to c95aeae Compare July 26, 2025 00:23
@jakepetroules jakepetroules changed the title Experiment: disable hanging tests Fix hang in ServiceConsoleTests.serviceShutdown Jul 26, 2025
@jakepetroules jakepetroules marked this pull request as ready for review July 26, 2025 00:24
@jakepetroules
Copy link
Collaborator Author

@swift-ci test

@jakepetroules jakepetroules force-pushed the eng/PR-hanging-tests branch from c95aeae to 996bcb1 Compare July 26, 2025 07:06
This hang occurred only in CI environments and only on Linux. Here's the sequence of events:

- Test terminates swbuild using SIGKILL
- OS reparents SWBBuildService (a subprocess of swbuild) to launchd (Darwin) / init (others)
- OS closes the file descriptors for the I/O pipes swbuild has connected to SWBBuildService
- SWBBuildService's read() loop indicates EOF due to the broken pipe
- SWBBuildService causes itself to exit

At this point, the getpgid loop should return ERSCH and terminate the test. However, SWBBuildService is sticking around as a zombie for an extended period of time without init reaping the pid, causing getpgid to never hit the termination state. This causes the test to hang indefinitely.

To fix this, there are two aspects:

- A timeout is added around the termination monitoring loop that forces the exit promise to be fulfilled with an error if a 30-second interval elapses without the process exiting
- We switch from using a getpgid loop to using a waitid loop, where the terminal state is that the process has _exited_... we don't care if the zombie hasn't been collected by init, only that it's not in a running state

This fixes the hang for both the Jenkins based CI as well as GitHub actions, and also insulates us against future hangs by ensuring the test will terminate with a timeout error instead of hanging indefinitely, so that we at least know _which_ test is the problem.
@jakepetroules jakepetroules force-pushed the eng/PR-hanging-tests branch from 996bcb1 to d852b97 Compare July 26, 2025 07:33
@jakepetroules
Copy link
Collaborator Author

@swift-ci test

@jakepetroules jakepetroules enabled auto-merge (rebase) July 26, 2025 08:14
import SystemPackage
#endif

@Suite(.skipHostOS(.windows))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Will this cause the entire suite to be skipped on Windows, including individual test functions that aren't marked as skip for Windows?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but note that this isn't new code. Many of these were broken on Windows which is why they were skipped en masse. We should work on getting them passing.

@jakepetroules jakepetroules merged commit bb039da into swiftlang:main Jul 28, 2025
22 of 24 checks passed
@jakepetroules jakepetroules deleted the eng/PR-hanging-tests branch July 28, 2025 18:35
jakepetroules added a commit to jakepetroules/swift-build that referenced this pull request Jul 29, 2025
Some of these were formerly skipped in GitHub actions, but are passing now. Likely the culprit was ServiceConsoleTests.serviceShutdown all along, which is fixed in swiftlang#673
jakepetroules added a commit that referenced this pull request Jul 30, 2025
Some of these were formerly skipped in GitHub actions, but are passing now. Likely the culprit was ServiceConsoleTests.serviceShutdown all along, which is fixed in #673
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants