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

Subscribable sources: try-catch onSubscribe and cleanup state if any #3046

Merged
merged 2 commits into from
Aug 21, 2024

Conversation

idelpivnitskiy
Copy link
Member

@idelpivnitskiy idelpivnitskiy commented Aug 20, 2024

Motivation:

All original sources that implement handleSubscribe method should protect from a buggy Subscriber that may unexpectedly throw from onSubscribe. If they have any state or resource, it should be cleaned up.

Modifications:

  • Find all Publisher/Single/Completable that implement handleSubscribe and use handleExceptionFromOnSubscribe utility;

The following sources clean up their state on exception:

  • FromInputStreamPublisher closes InputStream;
  • SpliceFlatStreamToMetaSingle cancels upstream Subscription;
  • TcpConnector signals ConnectionObserver.connectionClosed(t);
  • TcpServerBinder cancels bind Future and closes Channel if necessary;
  • NettyChannelPublisher registers fatalError and closes Channel;
  • DefaultNettyConnection, ChannelInitSingle, H2ClientParentConnectionContext, H2ServerParentConnectionContext close Channel;

Results:

  1. Best effort to propagate exception via reactive flow.
  2. Cleaning up resources.

Motivation:

All original sources that implement `handleSubscribe` method should
protect from a buggy `Subscriber` that may unexpectedly throw from
`onSubscribe`. If they have any state or resource, it should be cleaned
up.

Modifications:
- Find all `Publisher`/`Single`/`Completable` that implement
`handleSubscribe` and use `handleExceptionFromOnSubscribe` utility;

The following sources clean up their state on exception:
- `FromInputStreamPublisher` closes `InputStream`;
- `SpliceFlatStreamToMetaSingle` cancels upstream `Subscription`;
- `TcpConnector` signals `ConnectionObserver.connectionClosed(t)`;
- `TcpServerBinder` cancels bind `Future`;
- `NettyChannelPublisher` registers `fatalError` and closes `Channel`;
- `DefaultNettyConnection`, `ChannelInitSingle`,
`H2ClientParentConnectionContext`, `H2ServerParentConnectionContext`
close `Channel`;

Results:

1. Best effort to propagate exception via reactive flow.
2. Cleaning up resources.
Copy link
Contributor

@bryce-anderson bryce-anderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one change necessary in TcpServerBinder and then ship it.

@idelpivnitskiy idelpivnitskiy merged commit 8074930 into apple:main Aug 21, 2024
11 checks passed
@idelpivnitskiy idelpivnitskiy deleted the try-catch branch August 21, 2024 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants