Corrupted file served if file is changed during serving.
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- javascript, node.js, wasm
- Domain
- backend
Research direction
Start by reproducing the issue with the shown serveStatic(root) setup and a 100MB+ WASM file that changes while a request is in progress. Inspect the serve-static behavior involved in serving and reloading the file, then verify that a browser refresh receives the complete rebuilt file without restarting the server.
Written by the indexing model from the issue text.
Description
Hi, I've got such a code for my server:
import path from 'node:path'
import url from 'node:url'
import portfinder from 'portfinder'
import connect from 'connect'
import { WebSocketServer } from 'ws'
import serveStatic from 'serve-static'
import logger from 'morgan'
export const DEFAULT_PORT = 8080
let dirname = path.dirname(url.fileURLToPath(import.meta.url))
// Path of a file that needs to be injected into the bundle for live-reload to work.
export const LIVE_RELOAD_LISTENER_PATH = path.join(dirname, 'live-reload.js')
export async function start({ root, assets, port }) {
assets = assets ?? path.join(root, 'assets')
const freePort = await portfinder.getPortPromise({ port: port ?? DEFAULT_PORT })
const setHeaders = (res) => {
res.setHeader('Cache-Control', 'no-store')
}
const app = connect()
.use(logger('dev', { skip: (req, res) => res.statusCode < 400 }))
.use(serveStatic(root, {setHeaders}))
.use('/assets', serveStatic(assets, {setHeaders}))
const server = app.listen(freePort)
const wsServer = new WebSocketServer({ server, clientTracking: true, path: '/live-reload' })
var serverUrl = `http://localhost:${freePort}`
console.log('Serving %s', serverUrl)
return {
port: freePort,
reload() {
wsServer.clients.forEach(sock => sock.send('reload'))
},
}
}
And we have observed a very interesting behavior. Namely, when it is serving our WASM file (100MB+), if the WASM is being re-build just when serving starts, then it is served to the browser corrupted. What's interesting is that after it is rebuilt, browser refreshes dont help - the same corrupted file is being served. What helps is restarting the above server to serve non-corrupted file. Does anyone have any idea why this happens and if this can be prevented somehow? I'm OK with serving it in a corrupted state for the first time (during rebuild), but I want the file to be served correctly after page reload.
- Dominant language
- JavaScript
- Stars
- 1.4k
- Forks
- 240
- Avg merge
- 3d 21h
- Merged PRs (30d)
- 1
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing 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.
More from expressjs/serve-static
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
expressjs/serve-static#149 · 2 comments ·
-
too wide CSP header in redirect responsePossibly taken @Sumit-Mayani claimed this 191 days ago. Openbug investigate
Difficulty 4/5 3-5 days Newbie friendliness 25/100
expressjs/serve-static#187 · 9 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 38/100
expressjs/serve-static#138 · 1 comment · 3 reactions ·
-
awaiting more info
Difficulty 5/5 Over a week Newbie friendliness 30/100
expressjs/serve-static#136 · 8 comments ·
-
Disable symlinksPossibly taken @jayk claimed this 2576 days ago. Openenhancement
Difficulty 4/5 3-5 days Newbie friendliness 30/100
expressjs/serve-static#120 · 2 comments ·
All issues in expressjs/serve-static
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
wazuh/wazuh-documentation#10584 ·
Maintainers usually reply within 1 day
-
documentation good first issue
Difficulty 1/5 Under an hour Newbie friendliness 94/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
InukaAsith/TwinDesk#84 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Graphify-Labs/graphify#4860 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
CommandCodeAI/command-code#1088 ·
Maintainers usually reply within 2 days