Spring cloud gateway deployed in GCP App engine flexible causes infinite redirect loop

mx flag

I have a two services running in GCP app engine; let's say service A and B, and then I deployed a spring cloud gateway service to route external traffic to these two services based on path predicates. service A and B are deployed in app engine flexible. initially I had the gateway deployed in app engine flexible and it was working perfectly well. because we have some batch services which has response time of more than 10 mins (app engine standard has max-response-timeout of 10 mins), we had to decide to migrate the gateway to app engine flexible.

The gateway service is dockerized and runs in the port 8080. My app.yaml looks like this:

runtime: custom
env: flex

service: beta-gateway


  cpu: 1
  memory_gb: 2

  path: "/actuator/health"
  check_interval_sec: 30
  timeout_sec: 4
  failure_threshold: 2
  success_threshold: 2
  initial_delay_sec: 300

  path: "/actuator/health"
  check_interval_sec: 5
  timeout_sec: 4
  failure_threshold: 2
  success_threshold: 2
  app_start_timeout_sec: 300

The service gets deployed correctly, the actuator endpoints works perfectly, I call /actuator/gateway/routes end point and the routing config looks good (And I route it to the services A and B using the appshot dns uri; Not the best approach should use a service registry in future).

The Problem: The problem is that for any endpoint other that the actuator endpoint, the request goes in to a redirect(302) loop and eventually fails.

What I tried:

As mentioned above, I invoked the /actuator/gateway/routes end point and the routing config looks good. I enabled TRACE logging for gateway and I see that the routing is getting matched correctly to service A or B's appspot dns url. The looks looks like this:

2022-06-02 16:10:22.030 PDT tags: [tag(httpMethod=GET),tag(httpStatusCode=302),tag(outcome=REDIRECTION),tag(routeId=web_api_route),tag(routeUri=,tag(status=FOUND)]
2022-06-02 16:10:22.029 PDT
NettyWriteResponseFilter start inbound: 2ad7457b, outbound: [67187409-456]
2022-06-02 16:10:22.019 PDT
outbound route: 2ad7457b, inbound: [67187409-456]
2022-06-02 16:10:22.016 PDT
RouteToRequestUrlFilter start
2022-06-02 16:10:22.016 PDT
Sorted gatewayFilterFactories: [[GatewayFilterAdapter{}, order = -2147483648], [GatewayFilterAdapter{}, order = -2147482648], [GatewayFilterAdapter{}, order = -1], [GatewayFilterAdapter{}, order = 0], [GatewayFilterAdapter{}, order = 0], [GatewayFilterAdapter{}, order = 10000], [GatewayFilterAdapter{$NoLoadBalancerClientFilter@1acaf3d}, order = 10150], [GatewayFilterAdapter{}, order = 2147483646], GatewayFilterAdapter{$$Lambda$397/503642634@27508c5d}, [GatewayFilterAdapter{}, order = 2147483647], [GatewayFilterAdapter{}, order = 2147483647]]
2022-06-02 16:10:22.016 PDT
[67187409-456] Mapped to
2022-06-02 16:10:22.015 PDT
Mapping [Exchange: GET] to Route{id='web_api_route', uri=, order=0, predicate=Paths: [/**], match trailing slash: true, gatewayFilters=[], metadata={}}
2022-06-02 16:10:22.015 PDT
Route matched: web_api_route
2022-06-02 16:10:22.015 PDT
Pattern "/**" matches against value "/favicon.ico"
2022-06-02 16:10:22.015 PDT
Pattern "[/api/import-auphan/**, /api/import-speedline/**, /api/import-heartland/**, /api/import-clover/**, /api/import-toast/**]" does not match against value "/favicon.ico"
2022-06-02 16:10:22.015 PDT
Pattern "[/api/cloudprint/**]" does not match against value "/favicon.ico"

2022-06-02 16:10:22.015 PDT
Pattern "[/api/jobs/**]" does not match against value "/favicon.ico"
2022-06-02 16:10:22.014 PDT
Pattern "[/api/webhooks/**]" does not match against value "/favicon.ico"

I am not very sure if it is relevant, but I initially did a deployment with network setting specifying port binding

  name: default
    - 80:8080

I then learned that the binding to 8080 is done be default and removed it.

Any advice will be highly appreciated. Thank you!


Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.