Skip to content

[2.x] fix: Print server stderr on startup failure#8816

Merged
eed3si9n merged 1 commit intosbt:developfrom
eureka928:fix/8812-server-startup-error
Feb 26, 2026
Merged

[2.x] fix: Print server stderr on startup failure#8816
eed3si9n merged 1 commit intosbt:developfrom
eureka928:fix/8812-server-startup-error

Conversation

@eureka928
Copy link
Copy Markdown
Contributor

Fixes #8812

Summary

When the sbt server fails to start, print the actual error instead of only showing "failed to connect to server".

Problem

When the server process fails during auto-start (e.g. wrong JDK version producing UnsupportedClassVersionError), the client only prints:

[error] failed to connect to server

This hides the real cause. The --server flag shows the error because it uses inheritIO(), but the auto-start path redirects stderr to /dev/null (added in #8442 to prevent Linux pipe buffer deadlocks).

Solution

Redirect server stderr to a temp file instead of /dev/null. If the server fails to start (portfile never appears), read and print the temp file contents before throwing ServerFailedException. This preserves the #8442 fix (writing to a file avoids pipe buffer deadlocks) while capturing startup errors for diagnostics.

The temp file is cleaned up eagerly on both success and failure paths, with deleteOnExit() as a safety net.

Changes

  • main-command/.../NetworkClient.scala
    • Redirect server stderr to a temp file instead of /dev/null
    • On startup failure, read and print the temp file before throwing ServerFailedException
    • Delete the temp file eagerly after use (both success and failure paths)

**Problem**
When the sbt server fails to start (e.g. wrong JDK version), the client
only shows "failed to connect to server" hiding the actual error. The
server stderr is redirected to /dev/null to prevent Linux pipe buffer
deadlocks (sbt#8442), so diagnostic output is lost.

**Solution**
Redirect server stderr to a temp file instead of /dev/null. When the
server fails to start (portfile never appears), read and print the temp
file contents before throwing ServerFailedException. The temp file is
cleaned up eagerly on both success and failure paths.

Fixes sbt#8812
@eureka928
Copy link
Copy Markdown
Contributor Author

@eed3si9n Could you review this when you get a chance? This is a small fix for #8812 — redirects server stderr to a temp file instead of /dev/null so startup errors are visible to the user.

@eed3si9n eed3si9n merged commit 8d9a002 into sbt:develop Feb 26, 2026
15 checks passed
eed3si9n pushed a commit to eed3si9n/sbt that referenced this pull request Mar 1, 2026
**Problem**
When the sbt server fails to start (e.g. wrong JDK version), the client
only shows "failed to connect to server" hiding the actual error. The
server stderr is redirected to /dev/null to prevent Linux pipe buffer
deadlocks (sbt#8442), so diagnostic output is lost.

**Solution**
Redirect server stderr to a temp file instead of /dev/null. When the
server fails to start (portfile never appears), read and print the temp
file contents before throwing ServerFailedException. The temp file is
cleaned up eagerly on both success and failure paths.

Fixes sbt#8812
eed3si9n added a commit that referenced this pull request Mar 1, 2026
**Problem**
When the sbt server fails to start (e.g. wrong JDK version), the client
only shows "failed to connect to server" hiding the actual error. The
server stderr is redirected to /dev/null to prevent Linux pipe buffer
deadlocks (#8442), so diagnostic output is lost.

**Solution**
Redirect server stderr to a temp file instead of /dev/null. When the
server fails to start (portfile never appears), read and print the temp
file contents before throwing ServerFailedException. The temp file is
cleaned up eagerly on both success and failure paths.

Fixes #8812

Co-authored-by: Dream <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[2.x] "server was not detected" (server should print error)

2 participants