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

reactive: Reactive types must support side-effect handlers #3486

Closed
hidemikimura opened this issue Jul 26, 2024 · 5 comments
Closed

reactive: Reactive types must support side-effect handlers #3486

hidemikimura opened this issue Jul 26, 2024 · 5 comments

Comments

@hidemikimura
Copy link

It seems that something is being sent after the response is sent with Context.send() in CompletionStage.
Can the process here in io.jooby.internal.handler.apply() be changed?

      } else if (result instanceof CompletionStage future) {
        future.whenComplete(
            (value, x) -> {
              // Add the following if statement
              if (ctx.isResponseStarted()) {
                return;
              }
              try {
                Route.After after = ctx.getRoute().getAfter();
                if (after != null) {
                  // run after:
                  after.apply(ctx, value, unwrap((Throwable) x));
                }
                if (x != null) {
                  Throwable exception = unwrap((Throwable) x);
                  ctx.sendError(exception);
                } else {
                  ctx.render(value);
                }
              } catch (Throwable cause) {
                ctx.sendError(cause);
              }
            });
        // Return context to mark as handled
        return ctx;
      }
@jknack
Copy link
Member

jknack commented Jul 27, 2024

Hi, don't follow. what would you like to change?

@hidemikimura
Copy link
Author

Executing Context.send() within CompletionStage will raise an exception after the response.
Please make sure that no exception is raised.

@jknack
Copy link
Member

jknack commented Jul 30, 2024

Please add an example to reproduce the issue.

@hidemikimura
Copy link
Author

install(new NettyServer());
setExecutionMode(ExecutionMode.EVENT_LOOP);
use(ReactiveSupport.concurrent());

get("/", ctx -> CompletableFuture.supplyAsync(() -> {
	ctx.send("top page");
	return ctx;
}));

@jknack jknack added bug and removed question labels Aug 1, 2024
@jknack jknack changed the title CompletionStage: Context.send() in CompletionStage raises Exception reactive: Reactive types must support side-effect handlers Aug 1, 2024
@jknack jknack closed this as completed in 86f5c8e Aug 1, 2024
@jknack jknack added this to the 3.3.0 milestone Aug 1, 2024
@hidemikimura
Copy link
Author

Thanks for the correction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants