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

fix: create new readers and writer for every async request #10026

Merged
merged 1 commit into from Aug 8, 2022

Conversation

oleschoenburg
Copy link
Member

@oleschoenburg oleschoenburg commented Aug 8, 2022

Description

This allows async api handlers to get new instances of request readers and writers on every request, while synchronous handlers can re-use their writers and readers.

Related issues

closes #10014

Definition of Done

Not all items need to be done depending on the issue and the pull request.

Code changes:

  • The changes are backwards compatibility with previous versions
  • If it fixes a bug then PRs are created to backport the fix to the last two minor versions. You can trigger a backport by assigning labels (e.g. backport stable/1.3) to the PR, in case that fails you need to create backports manually.

Testing:

  • There are unit/integration tests that verify all acceptance criterias of the issue
  • New tests are written to ensure backwards compatibility with further versions
  • The behavior is tested manually
  • The change has been verified by a QA run
  • The impact of the changes is verified by a benchmark

Documentation:

  • The documentation is updated (e.g. BPMN reference, configuration, examples, get-started guides, etc.)
  • New content is added to the release announcement
  • If the PR changes how BPMN processes are validated (e.g. support new BPMN element) then the Camunda modeling team should be informed to adjust the BPMN linting.

Please refer to our review guidelines.

@oleschoenburg oleschoenburg force-pushed the 10014-create-reader-writers-on-request branch from 20b88d4 to cade08f Compare August 8, 2022 11:21
super(
() -> requestReader,
() -> responseWriter,
new Supplier<>() {
Copy link
Member Author

Choose a reason for hiding this comment

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

💭 Looks weird but I found no other way to define a supplier that always returns the same instance of errorResponseWriter

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry. Didn't see this comment before my review.

I think it is ok if it creates a new instance everytime.

Copy link
Contributor

@deepthidevaki deepthidevaki left a comment

Choose a reason for hiding this comment

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

Thanks.

Comment on lines +33 to +39
new Supplier<>() {
private final ErrorResponseWriter errorResponseWriter = new ErrorResponseWriter();

@Override
public ErrorResponseWriter get() {
return errorResponseWriter;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
new Supplier<>() {
private final ErrorResponseWriter errorResponseWriter = new ErrorResponseWriter();
@Override
public ErrorResponseWriter get() {
return errorResponseWriter;
}
() -> new ErrorResponseWriter()

Comment on lines +94 to +95
final var responseWriter = responseWriterSupplier.get();
final var errorResponseWriter = errorResponseWriterSupplier.get();
Copy link
Contributor

Choose a reason for hiding this comment

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

💭 I still think you don't have to create these instances here. Instead it can be created in the implementation of handleAsync. But this is ok for now. We can discuss it when you refactor this class.

@oleschoenburg
Copy link
Member Author

I'll merge this directly once jenkins runs through.

@oleschoenburg oleschoenburg merged commit 47c3d3a into main Aug 8, 2022
@oleschoenburg oleschoenburg deleted the 10014-create-reader-writers-on-request branch August 8, 2022 12:04
zeebe-bors-camunda bot added a commit that referenced this pull request Aug 9, 2022
10037: fix: create new readers and writer for every sync request r=oleschoenburg a=oleschoenburg

## Description

Applies the fix in #10026 for sync api handlers too.

Due to our actor scheduler, even sync handlers can't reuse readers andwriters because `onComplete` on the already completed future doesn't run immediately, causing a data race on the readers and writers when handling concurrent requests.

## Related issues

<!-- Which issues are closed by this PR or are related -->

closes #10014 



Co-authored-by: Ole Schönburg <ole.schoenburg@gmail.com>
zeebe-bors-camunda bot added a commit that referenced this pull request Aug 9, 2022
10037: fix: create new readers and writer for every sync request r=oleschoenburg a=oleschoenburg

## Description

Applies the fix in #10026 for sync api handlers too.

Due to our actor scheduler, even sync handlers can't reuse readers andwriters because `onComplete` on the already completed future doesn't run immediately, causing a data race on the readers and writers when handling concurrent requests.

## Related issues

<!-- Which issues are closed by this PR or are related -->

closes #10014 



Co-authored-by: Ole Schönburg <ole.schoenburg@gmail.com>
zeebe-bors-camunda bot added a commit that referenced this pull request Aug 9, 2022
10037: fix: create new readers and writer for every sync request r=oleschoenburg a=oleschoenburg

## Description

Applies the fix in #10026 for sync api handlers too.

Due to our actor scheduler, even sync handlers can't reuse readers andwriters because `onComplete` on the already completed future doesn't run immediately, causing a data race on the readers and writers when handling concurrent requests.

## Related issues

<!-- Which issues are closed by this PR or are related -->

closes #10014 



Co-authored-by: Ole Schönburg <ole.schoenburg@gmail.com>
@Zelldon Zelldon added the version:8.1.0 Marks an issue as being completely or in parts released in 8.1.0 label Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
version:8.1.0-alpha5 Marks an issue as being completely or in parts released in 8.1.0-alpha5 version:8.1.0 Marks an issue as being completely or in parts released in 8.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NullPointerException upon writing error response
3 participants