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

Metric - Http1xServerConnection request is null #4546

Closed
glassfox opened this issue Nov 20, 2022 · 6 comments · Fixed by #4556
Closed

Metric - Http1xServerConnection request is null #4546

glassfox opened this issue Nov 20, 2022 · 6 comments · Fixed by #4556
Labels
Milestone

Comments

@glassfox
Copy link

Below exception occurred for enabled metric:

java.lang.NullPointerException: Cannot invoke "io.vertx.core.http.impl.Http1xServerRequest.metric()" because "request" is null
    at io.vertx.core.http.impl.Http1xServerConnection.reportResponseComplete(Http1xServerConnection.java:253) 
    at io.vertx.core.http.impl.Http1xServerConnection.responseComplete(Http1xServerConnection.java:198) 
    at io.vertx.core.http.impl.Http1xServerResponse.end(Http1xServerResponse.java:415) 
    at io.vertx.core.http.impl.Http1xServerResponse.end(Http1xServerResponse.java:388) 
    at io.vertx.core.http.impl.Http1xServerResponse.end(Http1xServerResponse.java:367) 
    at io.vertx.ext.web.handler.impl.ErrorHandlerImpl.sendError(ErrorHandlerImpl.java:180) 

Occurred on vertx version: 4.3.4 and 4.3.5

@glassfox glassfox added the bug label Nov 20, 2022
@tsegismont tsegismont added this to the 4.4.0 milestone Nov 21, 2022
@tsegismont
Copy link
Contributor

@glassfox Does this happen all the time of for each and every request?

@glassfox
Copy link
Author

hi @tsegismont
After short investigation, has been found incorrect using of context.fail.
I not sure if this is a bug. Anyway this kind of implementation create recursion and fail in the end with NullPointer exception.

Following example of route:

router.route().handler(ctx -> {
	ctx.addHeadersEndHandler(c -> {
		...
		ctx.fail(555);
		...
	});
			
	ctx.next();
});

Let me know if you agree to close this bug.

@tsegismont
Copy link
Contributor

Please do not close yet. If you can add a little more details to the snippet, perhaps we can create a test and change our code to fail nicely instead of failing with a NPE.

@glassfox
Copy link
Author

Sure. I will create Unitest.

@tsegismont
Copy link
Contributor

tsegismont commented Nov 22, 2022 via email

@glassfox
Copy link
Author

import java.util.concurrent.atomic.AtomicBoolean;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
import io.vertx.core.Promise;
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
import io.vertx.core.http.RequestOptions;
import io.vertx.core.metrics.MetricsOptions;
import io.vertx.ext.web.Router;
import io.vertx.junit5.VertxExtension;
import io.vertx.junit5.VertxTestContext;

@ExtendWith(VertxExtension.class)
public class AppImplTest {

	@BeforeEach
	protected void setUp(Vertx vertx) throws Exception {
	}
	
	@Test
	void test(Vertx vertx, VertxTestContext testCtx) {
		AtomicBoolean flag = new AtomicBoolean();
		VertxOptions vertxOptions = new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true));
		Future.succeededFuture().map(Vertx.vertx(vertxOptions))
		.compose(myVertx -> 
			myVertx.deployVerticle(new AbstractVerticle() {
				@Override
				public void start(Promise<Void> startPromise) throws Exception {
					var router = Router.router(this.vertx);
					router.route().handler(ctx -> {
						ctx.addHeadersEndHandler(c-> {
							if(!flag.compareAndExchange(false, true)) {
								ctx.fail(555);
							}
						});
						ctx.end();
					});
					
					router.route().failureHandler(ctx -> {
						if(null != ctx.failure()) {
							testCtx.failNow(ctx.failure());
						}
						
						ctx.next();
						
					});
					
					this.vertx.createHttpServer()
					.requestHandler(router)
					.listen()
					.<Void>mapEmpty()
					.onComplete(startPromise);
				}
			}))
			.compose(nil -> 
				vertx.createHttpClient()
				.request(new RequestOptions())
				.compose(req -> req.send())
			)
			.onComplete(testCtx.succeedingThenComplete());
	}

}

@tsegismont tsegismont modified the milestones: 4.4.0, 4.3.6 Nov 23, 2022
tsegismont added a commit to tsegismont/vert.x that referenced this issue Dec 2, 2022
See eclipse-vertx#4546

This aligns behaviors of Http 1 and Http2 servers.

Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
tsegismont added a commit that referenced this issue Dec 5, 2022
See #4546

This aligns behaviors of Http 1 and Http2 servers.

Signed-off-by: Thomas Segismont <tsegismont@gmail.com>

Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
tsegismont added a commit to tsegismont/vert.x that referenced this issue Dec 5, 2022
…ipse-vertx#4549)

Fixes eclipse-vertx#4546

This aligns behaviors of Http 1 and Http2 servers.

Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
tsegismont added a commit that referenced this issue Dec 5, 2022
…) (#4556)

Fixes #4546

This aligns behaviors of Http 1 and Http2 servers.

Signed-off-by: Thomas Segismont <tsegismont@gmail.com>

Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
@vietj vietj modified the milestones: 4.3.6, 4.4.0 Dec 6, 2022
@vietj vietj closed this as completed Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants