我们有一个在谷歌云上运行的快速服务器。当我们的服务器尝试使用 204 的 HTTP 状态代码进行响应时,这将转换为 502 Bad Gateway。我已经确认这只发生在 GCP 中。在这个特定示例中,我们使用的是 Google 的完全托管端点。在我的本地机器上运行它会产生预期的结果。此外,使用相同的代码发送 200 状态代码也可以成功。
错误代码:upstream connect error or disconnect/reset before headers. reset reason: protocol error
这是我们以 204 状态码响应的 express 端点:
app.post('/', [cors(corsConfig), jsonParser], async (req, res) => {
res.setTimeout(timeout, () => {
log(’timeout’)
res.sendStatus('204');
res.end();
});
});
连接细节:
- 利用 Google 的托管端点
- HTTP/2禁用
这是我们的 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" ]