spring-cloud / spring-cloud-gateway

An API Gateway built on Spring Framework and Spring Boot providing routing and more.
http://cloud.spring.io
Apache License 2.0
4.55k stars 3.33k forks source link

StripPrefixGatewayFilter using wrong parts to rebuild path causes routing 404 #3587

Open chengyouling opened 2 weeks ago

chengyouling commented 2 weeks ago

Exception phenomenon: The value is expected to be StripPrefix=2 to rebuild path in the router, however, in some scenarios using StripPrefix=1. This problem occurs occasionally in high-concurrency scenarios, and the target service address is correct by lb.

Similar issues in history https://github.com/spring-cloud/spring-cloud-gateway/issues/3215

Gateway version: 2.1.3.RELEASE

Router config:

spring:
  cloud:
    gateway:
      routes:
        - id: consumer
          uri: lb://basic-consumer
          predicates:
            - Path=/api/template/**
          filters:
            - StripPrefix=2

logs

2024-11-07 12:56:45.846 ERROR [notary-cloud-gateway,bdc3393ef21cf030462f3e197c1589c2,d42baa8dcddc6db9,true] 8 --- [reactor-http-epoll-2@] c.n.g.Exception.JsonExceptionHandler     : Failed to handle request [POST http://nc-gateway.fxnotary.com/api/template/templateModel/findTemplateModelByCode]: syntax error, pos 1, line 1, column 2<html><body><h1>Whitelabel Error Page</h1><p>This application has no explicit mapping for /error, so you are seeing this as a fallback.</p><div id='created'>Thu Nov 07 12:56:44 CST 2024</div><div>There was an unexpected error (type=Not Found, status=404).</div><div>Not Found</div></body></html>

The new path after StripPrefixGatewayFilter logs, the uri address is the basic-consumer service instance exists.

2024-11-07 12:56:44.823 DEBUG [notary-cloud-gateway,,,] 8 --- [reactor-http-epoll-2@] r.netty.http.client.HttpClientConnect    : [id: 0x23b0f6fb, L:/10.10.35.51:58378 - R:10.10.11.225/10.10.11.225:8080] Handler is being applied: {uri=http://10.10.11.225:8080/template/templateModel/findTemplateModelByCode, method=POST}

Looking forward to your reply.

Thank you!

spencergibb commented 2 weeks ago

Unfortunately, that version is no longer supported. Can you recreate the issue in the latest version?

chengyouling commented 1 week ago

Thank you for your reply, how can I raise an issue in the latest version?