Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sbt in --client mode loses stdout/stderr of the forked processes in continuous (watch) task mode after the task ir reevaluated #7527

Open
arturaz opened this issue Apr 7, 2024 · 0 comments
Labels

Comments

@arturaz
Copy link
Contributor

arturaz commented Apr 7, 2024

  • sbt: 1.9.9
  • JVM: 21

It seems that sbt --client has a problem losing stdout/stderr when a task is re-evaluated in the watch mode.

This is somewhat obscure, as the task has to launch a process in the background using the Fork API. It was originally noticed in sbt-revolver plugin (spray/sbt-revolver#99). After quick investigation it seems that sbt-revolver does not do anything fancy, except launching the forked process (https://github.com/spray/sbt-revolver/blob/4d28f091d3f2ce2f7f28b0165bac6705effded9a/src/main/scala/spray/revolver/Actions.scala#L139).

Reproduction case: https://github.com/arturaz/sbt-watch-loses-stdout

Expected behaviour

If we launch sbt in non-client mode everything works as expected:

PS E:\projects\sbt-watch-loses-stdout> sbt
[info] welcome to sbt 1.9.9 (Oracle Corporation Java 21.0.1)
[info] loading global plugins from C:\Users\x11\.sbt\1.0\plugins
[info] loading settings for project sbt-watch-loses-stdout-build-build-build from metals.sbt ...
[info] loading project definition from E:\projects\sbt-watch-loses-stdout\project\project\project
[info] loading settings for project sbt-watch-loses-stdout-build-build from metals.sbt ...
[info] loading project definition from E:\projects\sbt-watch-loses-stdout\project\project
[success] Generated .bloop\sbt-watch-loses-stdout-build-build.json
[success] Total time: 2 s, completed 2024-04-07 14:44:54
[info] loading settings for project sbt-watch-loses-stdout-build from metals.sbt,plugins.sbt ...
[info] loading project definition from E:\projects\sbt-watch-loses-stdout\project
[success] Generated .bloop\sbt-watch-loses-stdout-build.json
[success] Total time: 1 s, completed 2024-04-07 14:44:56
[info] loading settings for project sbt-watch-loses-stdout from build.sbt ...
[info] set current project to sbt-watch-loses-stdout (in build file:/E:/projects/sbt-watch-loses-stdout/)
[info] sbt server started at local:sbt-server-88c85ad2cae54cd28c14
[info] started sbt server
sbt:sbt-watch-loses-stdout> ~reStart
[info] compiling 1 Scala source to E:\projects\sbt-watch-loses-stdout\target\scala-2.12\classes ...
[warn] one deprecation (since 2.11.0); re-run with -deprecation for details
[warn] one warning found
[info] Application sbt-watch-loses-stdout not yet started
[info] Starting application sbt-watch-loses-stdout in the background ...
sbt-watch-loses-stdout Starting app.Main.main()
[success] Total time: 3 s, completed 2024-04-07 14:45:54
[info] 1. Monitoring source files for sbt-watch-loses-stdout/reStart...
[info]    Press <enter> to interrupt or '?' for more options.
sbt-watch-loses-stdout Hello, World!
sbt-watch-loses-stdout ... finished with exit code 0
[info] Build triggered by E:\projects\sbt-watch-loses-stdout\src\main\scala\app\Main.scala. Running 'reStart'.
[info] compiling 1 Scala source to E:\projects\sbt-watch-loses-stdout\target\scala-2.12\classes ...
[warn] one deprecation (since 2.11.0); re-run with -deprecation for details
[warn] one warning found
[info] Application sbt-watch-loses-stdout not yet started
[info] Starting application sbt-watch-loses-stdout in the background ...
sbt-watch-loses-stdout Starting app.Main.main()
[success] Total time: 1 s, completed 2024-04-07 14:46:04
[info] 2. Monitoring source files for sbt-watch-loses-stdout/reStart...
[info]    Press <enter> to interrupt or '?' for more options.
sbt-watch-loses-stdout Hello, World!
sbt-watch-loses-stdout ... finished with exit code 0

Notice that "Hello, World!" is printed every time sbt-revolver restarts the background process.

Problem

However, if we launch it with sbt --client, this behaviour breaks down.

PS E:\projects\sbt-watch-loses-stdout> sbt --client
[info] entering *experimental* thin client - BEEP WHIRR
[info] server was not detected. starting an instance
[info] welcome to sbt 1.9.9 (Oracle Corporation Java 21.0.1)
[info] loading global plugins from C:\Users\x11\.sbt\1.0\plugins
[info] loading settings for project sbt-watch-loses-stdout-build-build-build from metals.sbt ...
[info] loading project definition from E:\projects\sbt-watch-loses-stdout\project\project\project
[info] loading settings for project sbt-watch-loses-stdout-build-build from metals.sbt ...
[info] loading project definition from E:\projects\sbt-watch-loses-stdout\project\project
[success] Generated .bloop\sbt-watch-loses-stdout-build-build.json
[success] Total time: 2 s, completed 2024-04-07 14:51:43
[info] loading settings for project sbt-watch-loses-stdout-build from metals.sbt,plugins.sbt ...
[info] loading project definition from E:\projects\sbt-watch-loses-stdout\project
[success] Generated .bloop\sbt-watch-loses-stdout-build.json
[success] Total time: 1 s, completed 2024-04-07 14:51:44
[info] loading settings for project sbt-watch-loses-stdout from build.sbt ...
[info] set current project to sbt-watch-loses-stdout (in build file:/E:/projects/sbt-watch-loses-stdout/)
[info] sbt server started at local:sbt-server-88c85ad2cae54cd28c14
[info] started sbt server
[info] terminate the server with `shutdown`
[info] disconnect from the server with `exit`
sbt:sbt-watch-loses-stdout> ~reStart
[info] Application sbt-watch-loses-stdout not yet started
[info] Starting application sbt-watch-loses-stdout in the background ...
sbt-watch-loses-stdout Starting app.Main.main()
[success] Total time: 0 s, completed 2024-04-07 14:51:48
[info] 1. Monitoring source files for sbt-watch-loses-stdout/reStart...
[info]    Press <enter> to interrupt or '?' for more options.
sbt-watch-loses-stdout Hello, World!
sbt-watch-loses-stdout ... finished with exit code 0
[info] Build triggered by E:\projects\sbt-watch-loses-stdout\src\main\scala\app\Main.scala. Running 'reStart'.
[info] compiling 1 Scala source to E:\projects\sbt-watch-loses-stdout\target\scala-2.12\classes ...
[warn] one deprecation (since 2.11.0); re-run with -deprecation for details
[warn] one warning found
[info] Application sbt-watch-loses-stdout not yet started
[info] Starting application sbt-watch-loses-stdout in the background ...
sbt-watch-loses-stdout Starting app.Main.main()
[success] Total time: 3 s, completed 2024-04-07 14:51:55
[info] 2. Monitoring source files for sbt-watch-loses-stdout/reStart...
[info]    Press <enter> to interrupt or '?' for more options.

Only the first run prints "Hello, World!", while the subsequent runs do not have any stdout/stderr output anymore.

Expectation

sbt and sbt --client should act identically.

Notes

eed3si9n — Yesterday at 8:29 PM
~ used to be defined mostly in one file https://github.com/sbt/sbt/blob/1.10.x/main/src/main/scala/sbt/internal/Continuous.scala. I am not sure if that's the case lately. in any case, feel free to open an issue on sbt/sbt so other maintainers may be able to take a look

I would be interested in fixing this issue if more guidance would be provided.

This might also be related: #6866

@arturaz arturaz added the Bug label Apr 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant