Open Source API Gateway

500 Internal Server Error: Could Not Get Session Id

Membrane API Gateway returns 500 Internal Server Error with the detail Could not get session id! when the session id extractor of the balancer plugin fails on the backend's response. The response of the backend is replaced with this error. The cause is the backend response or the extractor configuration.

The Error Response

The error happens in the response flow, so the client receives 500 Internal Server Error instead of the backend's response. The response contains the detail Could not get session id!, the problem type https://membrane-api.io/problems/internal and a link to this page. The type internal means that the gateway failed while processing the exchange.

Why the Balancer Extracts Session Ids

For sticky sessions, the balancer reads a session id from each message and sends later requests of the same session to the same node. The extractor is configured on the balancer, for example:

api:
port: 2000
flow:
- balancer:
xmlSessionIdExtractor:
localName: session
namespace: http://example.com/session
clusters:
- name: Default
nodes:
- host: node1.example.com
port: 8080
api:
  port: 2000
  flow:
    - balancer:
        xmlSessionIdExtractor:
          localName: session
          namespace: http://example.com/session
        clusters:
          - name: Default
            nodes:
              - host: node1.example.com
                port: 8080

Common Causes

The XML Response Is Not Well-Formed

With xmlSessionIdExtractor, the response is declared as XML but is not well-formed, or the session id element contains child elements instead of text.

The Expression Cannot Be Evaluated

With sessionIdExtractor, the expression in sessionSource cannot be evaluated against the response, for example because a function is unknown or the body does not have the expected format.

The Response Body Could Not Be Read

The backend closed the connection before the body was complete.

How to Fix It

  1. Check the gateway log and the detail in development mode to see which extractor failed and why.
  2. Correct the extractor configuration, or make it robust against responses that do not carry a session id.
  3. Fix the backend if it sends malformed XML or incomplete bodies.

Hide Details in Production

By default, Membrane runs in development mode and adds details to error responses that help you find the problem, including the link to this page. These details may reveal information about your setup. In production, turn them off:

configuration:
production: true
configuration:
  production: true

Add the configuration document to your apis.yaml and separate it from the APIs with ---.

In production mode, the title of this error is replaced by Internal Server Error, and the response only says Internal details are hidden. See server log (key: ...). Search the gateway log for that key to find the full error message.

Related Documentation

Configuration reference:

← All Membrane error messages

Still stuck? See the troubleshooting guide or ask on GitHub Issues. For commercial support, contact info@predic8.de.