-
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
Exception in client's Listener.onNewData
can crash SerialInputOutputManager
#601
Comments
Listener.onNewData
can crush SerialInputOutputManager
Listener.onNewData
can crash SerialInputOutputManager
First ideas:
|
My first idea was the same like yours - wrapping it in try {
listener.onNewData(data);
} catch (Exception e) {
// Do not wrap normal Exceptions
throw e;
} catch (Throwable t) {
throw new Exception("Client exception in Listener.onNewData", t);
} so Letting the "normal" exception fly freely is important for backwards compatibility - the existing clients might have handing in their I ask myself is |
…601) to avoid breaking Interface changes, Error from onNewData() is wrapped into Exception when calling onRunError()
…601) to avoid breaking Interface changes, Error from onNewData() is wrapped into Exception when calling onRunError()
…601) to avoid breaking Interface changes, Error from onNewData() is wrapped into Exception when calling onRunError()
Wow, you already patched it. That was quick! I thought I'd have to do the job and you only review :) Nice! But I see few problems with this approach. Not something critical, but maybe worth revisiting:
Like I said, it's not something critical critical but it would improve the quality even more. Do you think it's worth further discussion? If we decide to invest more effort into this, I can prepare the PR for your review. |
Low-level exceptions in client's
Listener.onNewData
can crashSerialInputOutputManager
.Impact
After this fault, no further RX is accepted and delivered to the
Listener
. The TX works, however. No recovery possible, the comm stack needs to be re-created. As the whole thing happens silently, this situation is very difficult to detect and debug.Reproducing
Steps
Listener.onNewData
throw anError
or a custom exception extendingThrowable
Expected result
Listener.onRunError
is calledActual result
Listener.onRunError
is NOT called.Minimal reproducible example
Full compilable runnable code can be found in the attached test.zip
Cause
The issue is caused by a too narrow scope of the
catch
clause inSerialInputOutputManager.run
which catches subclasses ofException
only. However, quite a number of lower level errors in Java do not extendException
but ratherError
- those will not be caught.Also, custom exceptions are not limited to extend
Exception
, so such a custom exception extendingThrowable
will not be caught too.Possible solutions
step
, wrap the invocation ofListener.onNewData
withtry-catch (Throwable)
Wrapping
Listener.onRunError
in the same manner may also be a good idearun
, expand the scope fromcatch (Exception e)
tocatch (Throwable e)
run
, add clausecatch (Throwable e)
"for bad cases"I recommend solution 1.
Action points
Let's quickly discuss the pros/cons of solutions, and once the option is selected I shall draft the PR with fix.
The text was updated successfully, but these errors were encountered: