Expiration of the request when hosted on Firebase / Route Handlers POST
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 142k
- Forks
- 32.4k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 351
Description
Verify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 22.4.0: Mon Mar 6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000
Binaries:
Node: 18.15.0
npm: 9.5.0
Yarn: N/A
pnpm: N/A
Relevant packages:
next: 13.4.4-canary.0
eslint-config-next: 13.4.3
react: 18.2.0
react-dom: 18.2.0
typescript: 5.0.4
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true)
Link to the code that reproduces this issue or a replay of the bug
https://github.com/slecoustre-vulog/bug-route-handler
To Reproduce
index.js
const {
https: { onRequest },
scheduler: { onSchedule },
logger,
} = require('firebase-functions/v2');
const { initializeApp } = require('firebase-admin/app');
const next = require('next');
const https = require('https');
const tools = require('normalize-diacritics');
const { parse } = require('url');
const LRU = require('lru-cache');
initializeApp();
const nextConfig = require('./next.config');
const nextAppsLRU = new LRU({
// TODO tune this
max: 3,
allowStale: true,
updateAgeOnGet: true,
dispose: (server) => {
server.close();
},
});
exports.web = onRequest(
{
concurrency: 300,
region: 'europe-west1',
minInstances: 1,
memory: '1GiB', // '512MB',
},
async (req, res) => {
const { hostname, protocol, url } = req;
const port = protocol === 'https' ? 443 : 80;
const key = [hostname, port].join(':');
let nextApp = nextAppsLRU.get(key);
if (!nextApp) {
nextApp = next({
...nextConfig,
dir: process.cwd(),
hostname,
port: process.env.NODE_ENV === 'development' ? 5001 : port,
});
nextAppsLRU.set(key, nextApp);
}
await nextApp.prepare();
const parsedUrl = parse(url, true);
await nextApp.getRequestHandler()(req, res, parsedUrl);
}
);
src/app/api/route.ts
import { NextRequest, NextResponse } from 'next/server';
export const GET = () => NextResponse.json({ message: 'Hello, world!' });
export const POST = async (req: NextRequest) => NextResponse.json({ message: 'Hello, world!', body: await req.json() });
Describe the Bug
During development everything works fine (npm run dev) but when you build and execute everything in firebase it doesn't work anymore.
but the same development worked very well in version 13.2.
in version :
- 13.4.2, I have the error: TypeError: Response body object should not be disturbed or locked
- canary, I have a timeout of 60s
If there is no Body then it works very well.
Expected Behavior
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Firebase Functions entry point in index.js and the POST route in src/app/api/route.ts. Reproduce the built application with Firebase, comparing POST requests with and without a body against the development behavior. Done means POST requests with a body complete successfully without the response-body error or timeout.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- firebase, javascript, next.js, typescript
- Domain
- api, backend, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100