Skip to content

Comments

[digiplex] Fix exception handling in sender and receiver threads#17829

Closed
rmichalak wants to merge 1 commit intoopenhab:mainfrom
rmichalak:17828-improve-digiplex-error-handling
Closed

[digiplex] Fix exception handling in sender and receiver threads#17829
rmichalak wants to merge 1 commit intoopenhab:mainfrom
rmichalak:17828-improve-digiplex-error-handling

Conversation

@rmichalak
Copy link
Contributor

Improves error handling in sender and receiver threads so that the threads do not occasionally stop when an unexpected exception occurs.

Closes #17828

@rmichalak rmichalak force-pushed the 17828-improve-digiplex-error-handling branch from 416f9d4 to b9cbdec Compare December 1, 2024 14:12
Signed-off-by: Robert Michalak <rbrt.michalak@gmail.com>
@rmichalak rmichalak force-pushed the 17828-improve-digiplex-error-handling branch from b9cbdec to 2d6ab72 Compare December 1, 2024 14:16
@jlaur
Copy link
Contributor

jlaur commented Dec 3, 2024

Improves error handling in sender and receiver threads so that the threads do not occasionally stop when an unexpected exception occurs.

Which unexpected exception have you observed?

@rmichalak
Copy link
Contributor Author

Improves error handling in sender and receiver threads so that the threads do not occasionally stop when an unexpected exception occurs.

Which unexpected exception have you observed?

Honestly, I don't remember now. I'm the original author of this binding and I had this fix applied in my environment for a long time (just forgot to push it to remote). As far as I remember, my alarm system is sending some rubbish over RS232 from time to time and then parsing may fail in many unexpected ways. that's why I have this handleCommunicationError function which reinitializes everything.

@lolodomo lolodomo added rebuild Triggers Jenkins PR build bug An unexpected problem or unintended behavior of an add-on and removed rebuild Triggers Jenkins PR build labels Dec 3, 2024
@lsiepel lsiepel requested a review from a team December 5, 2024 21:56
@jlaur
Copy link
Contributor

jlaur commented Dec 5, 2024

I'm the original author of this binding and I had this fix applied in my environment for a long time (just forgot to push it to remote). As far as I remember, my alarm system is sending some rubbish over RS232 from time to time and then parsing may fail in many unexpected ways

It seems that this fix will potentially hide parser bugs, for example StringIndexOutOfBoundsException here:

when message.length() is 4:

If you cannot fix that now, perhaps you could catch it closer to where it is expected to happen:

and log it so that "evidence" could be collected for further analysis and fixing. For example, something like this:

        DigiplexResponse response;
        try {
            response = DigiplexResponseResolver.resolveResponse(message);
        } catch (Exception e) {
            logger.warn("Failed to parse response. This is a bug.", e);
            return;
        }

Maybe you also need to call handleCommunicationError() before returning, if indeed the issue with parsing is caused by RS232 rubbish as you wrote.

WDYT?

@jlaur
Copy link
Contributor

jlaur commented Dec 8, 2024

It seems that this fix will potentially hide parser bugs

I fixed those parser bugs in #17864 and added test coverage and logging.

Maybe you also need to call handleCommunicationError() before returning, if indeed the issue with parsing is caused by RS232 rubbish as you wrote.

I don't think this is relevant after all. The parser already returned UnknownResponse when message was too short, which did not trigger any communication error and reinitialization. If that was not needed, it should not be needed for other malformed messages either. Hopefully the logging can help exposing such messages, but of course it would require you to enable debug logging probably for a longer period.

@jlaur
Copy link
Contributor

jlaur commented Jan 8, 2025

Superceded by #18035.

@jlaur jlaur closed this Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug An unexpected problem or unintended behavior of an add-on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[digiplex] Received thread stops when an exception happens inside

3 participants