expressjs / expressjs/session

Chrome/FF follow redirect before session is fully saved

Open
#360 28 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
6.4k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

Here's a simple testcase incrementing a counter: https://gist.github.com/antishok/fb3d003d16eb72f672a7cc36401657d9
On chrome I have to refresh after incrementing in order to see the new count.

In response to a request, I write to the session and send a redirect to another page, but the new page is rendered with the _old_ session data, and the changes I just wrote are not visible. The new data appears only after refreshing the page.

This only happens in Chrome, maybe due to an optimization they added that follows a redirect before the redirect response even ended.

I'm using `connect-session-knex` with postgresql to store my session data. If I use the MemoryStore, or use sqlite3 instead of postgresql, it works fine, but probably only because writing to them is much quicker.

The gist also includes debug logs for the request (one when I tested with chrome, and one with firefox). You can see that for chrome, the new url is fetched _before_ the session has finished saving, and before the redirect response ends.
(The logs include a log I manually added in the beginning of `express-session`'s `writeend()` function, to indicate when a response actually ends)

Thanks! And thanks to @joepie91 for figuring out where the issue lies

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.