-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[Breaking Change Request] Throw StateError in meaningless getters on detached processes #40483
Comments
This breaking change is currently landed in the NNBD-migrated SDK, but not the regular SDK. It would be prudent to land this breaking change in the regular SDK prior to unforking the SDK to avoid blocking problems at that time. If this breaking change cannot be made, the NNBD-migrated SDK will need to be changed to make the getters nullable. I will be unavailable next week. Depending on the NNBD unforking schedule, someone else may need to take over landing this breaking change if it's approved. |
One thing to note here is you can't easily (as far as I can tell) check whether a process instance is detached or not - so you essentially have to fall back on a try/catch for any api which accepts a If that sort of api is relatively uncommon though it might not matter. |
cc @Hixie @matanlurey @dgrove for review and approval. |
Seems fine |
lgtm for dart |
Thanks for the approval. I'll go ahead and land this breaking change tomorrow. |
This is a breaking change. #40483 The Process class will now throw a StateError if the process is detached upon accessing the exitCode getter. It now also throws when not connected to the child process's stdio upon accessing the stdin, stdout, and stderr getters. Previously these getters would all return null. The getters in question are meaningless for detached processes and there is no reason to use them in that case. To provide a better experience when Dart becomes null-safe, these getters are changed to throw and never return null, which avoids all legitimate uses of the getters from needing a null check that will never fail. The NNBD migration required making subtle changes to some dart:io semantics in order to provide a better API. This change backports one of these semantic changes to the unmigrated SDK so any issues can be discovered now instead of blocking the future SDK unfork. Change-Id: I776e0dc8bcd517d70332c60dd8ab88db17746aa5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134329 Commit-Queue: Jonas Termansen <sortie@google.com> Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
I've now landed this change. See the mitigation instructions above if there is any breakage.
You can catch the |
This is exactly the problem - you can't always know. In the case of Any api which has to deal with a process that it didn't spawn can't know in what mode it was spawned 🤷♂️ . |
This is probably not the right place to discuss that particular issue. I do understand how this change broke In general, you can't do anything meaningful given an arbitrary |
Intended change
The
Process
class will now throw aStateError
if the process is detached (ProcessStartMode.detached
andProcessStartMode.detachedWithStdio
) upon accessing theexitCode
getter. It now also throws when not connected to the child process's stdio (ProcessStartMode.detached
andProcessStartMode.inheritStdio
) upon accessing thestdin
,stdout
, andstderr
getters. Previously these getters would all returnnull
.Rationale
Child processes started with
ProcessStartMode.detached
orProcessStartMode.detachedWithStdio
are detached and the current process is not notified when the child exits. TheProcess.exitCode
getter is meaningless in this case and currently returnsnull
.Likewise child processes started with
ProcessStartMode.detached
orProcessStartMode.inheritStdio
do not have pipes connected and theProcess.stdin
,Process.stdout
, andProcess.stderr
getters are meaningless and currently returnnull
.As part of the effort to make Dart null-safe, we would like to make these getters throw a
StateError
in these cases instead. This change would allow us to mark theProcess.exitCode
,Process.stdin
,Process.stdout
, andProcess.stderr
getters as non-null. The alternative is to mark the getters as nullable, however all meaningful uses of the getters will always be non-null, yet all those uses would be required to check for null. We would like avoid those null checks that will never fail by making the getters non-nullable because we throw instead.Expected impact
package:bazel_worker
prior to0.1.23+1
was accessing theexitCode
getter on a detached process, but did nothing with it, which now crashes with aStateError
("Bad state: Process is detached") as of this breaking change. Upgrade tobazel_worker-0.1.23+1
or later to fix the issue.Otherwise it did not make sense to use these getters when they could be null and such uses should be very rare.
Steps for mitigation
If
package:bazel_worker
is failing with aStateError
("Bad state: Process is detached"), then upgrade tobazel_worker-0.1.23+1
or later to fix the problem.If any code is checking whether a
Process
is detached by checking if these getters returnnull
, it will need to be changed to check if aStateError
is thrown.Implementation
A proposed implementation of this breaking change: https://dart-review.googlesource.com/c/sdk/+/134329
cc @franklinyow @mit-mit @lrhn @athomas
The text was updated successfully, but these errors were encountered: