We have an express server that runs on google cloud run. When our server attempts to respond with a HTTP status code of 204 this gets transformed into 502 Bad Gateway. I have confirmed that this is only happening in GCP. In this specific example, we are using Google's fully managed endpoint. Running this on my local machine yields the expected results. Also, sending a 200 status code works successfully with the same code.
Error code: upstream connect error or disconnect/reset before headers. reset reason: protocol error
Here is our express endpoint that responds with the 204 status code:
app.post('/', [cors(corsConfig), jsonParser], async (req, res) => {
res.setTimeout(timeout, () => {
log(’timeout’)
res.sendStatus('204');
res.end();
});
});
Connection details:
- Utilizing Google's managed endpoint
- HTTP/2 disabled
here is our Dockerfile:
# Use the official lightweight Node.js 12 image.
# https://hub.docker.com/_/node
FROM node:12-slim AS base
# Create and change to the app directory.
WORKDIR /usr/src/app
# Run our webpack build inside a separate stage
FROM base AS build
# Copy application dependency manifests to the container image.
# A wildcard is used to ensure both package.json AND package-lock.json are copied.
# Copying this separately prevents re-running npm install on every code change.
COPY package*.json ./
COPY yarn.lock ./
# Install all dependencies for a build
RUN yarn
COPY . ./
RUN yarn build
FROM base AS runtime
COPY package*.json ./
COPY yarn.lock ./
# Copy only the built app output
COPY --from=build /usr/src/app/dist ./dist
# Re-install only production dependencies, to reduce image size ($$)
RUN yarn --only=production
COPY public ./public
COPY partners.yml ./
# Run the web service on container startup.
CMD [ "yarn", "start" ]