{"action":"created","issue":{"url":"https://api.github.com/repos/expressjs/session/issues/360","repository_url":"https://api.github.com/repos/expressjs/session","labels_url":"https://api.github.com/repos/expressjs/session/issues/360/labels{/name}","comments_url":"https://api.github.com/repos/expressjs/session/issues/360/comments","events_url":"https://api.github.com/repos/expressjs/session/issues/360/events","html_url":"https://github.com/expressjs/session/issues/360","id":176181118,"number":360,"title":"Chrome follows redirect before session is fully saved","user":{"login":"antishok","id":1644031,"avatar_url":"https://avatars.githubusercontent.com/u/1644031?v=3","gravatar_id":"","url":"https://api.github.com/users/antishok","html_url":"https://github.com/antishok","followers_url":"https://api.github.com/users/antishok/followers","following_url":"https://api.github.com/users/antishok/following{/other_user}","gists_url":"https://api.github.com/users/antishok/gists{/gist_id}","starred_url":"https://api.github.com/users/antishok/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antishok/subscriptions","organizations_url":"https://api.github.com/users/antishok/orgs","repos_url":"https://api.github.com/users/antishok/repos","events_url":"https://api.github.com/users/antishok/events{/privacy}","received_events_url":"https://api.github.com/users/antishok/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2016-09-10T14:00:36Z","updated_at":"2016-09-11T05:17:05Z","closed_at":null,"body":"Here's a simple testcase incrementing a counter: https://gist.github.com/antishok/fb3d003d16eb72f672a7cc36401657d9\r\nOn chrome I have to refresh after incrementing in order to see the new count.\r\n\r\nIn 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.\r\n\r\nThis only happens in Chrome, maybe due to an optimization they added that follows a redirect before the redirect response even ended.\r\n\r\nI'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.\r\n\r\nThe 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.\r\n(The logs include a log I manually added in the beginning of `express-session`'s `writeend()` function, to indicate when a response actually ends)\r\n\r\nThanks!  And thanks to @joepie91 for figuring out where the issue lies"},"comment":{"url":"https://api.github.com/repos/expressjs/session/issues/comments/246162526","html_url":"https://github.com/expressjs/session/issues/360#issuecomment-246162526","issue_url":"https://api.github.com/repos/expressjs/session/issues/360","id":246162526,"user":{"login":"joepie91","id":1663259,"avatar_url":"https://avatars.githubusercontent.com/u/1663259?v=3","gravatar_id":"","url":"https://api.github.com/users/joepie91","html_url":"https://github.com/joepie91","followers_url":"https://api.github.com/users/joepie91/followers","following_url":"https://api.github.com/users/joepie91/following{/other_user}","gists_url":"https://api.github.com/users/joepie91/gists{/gist_id}","starred_url":"https://api.github.com/users/joepie91/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joepie91/subscriptions","organizations_url":"https://api.github.com/users/joepie91/orgs","repos_url":"https://api.github.com/users/joepie91/repos","events_url":"https://api.github.com/users/joepie91/events{/privacy}","received_events_url":"https://api.github.com/users/joepie91/received_events","type":"User","site_admin":false},"created_at":"2016-09-11T05:17:05Z","updated_at":"2016-09-11T05:17:05Z","body":"> Couldn't this be avoided by adding req.session.save() right after line#30\r\n\r\nYes, it could, but this would be a leaky abstraction and a footgun.\r\n\r\n> but I feel like buffering the entire request and waiting for a full write for anyone who redirects isn't exactly good performance wise either\r\n\r\nI understand the concerns, but this would not be any different when calling `save` manually - you *still* have to wait for the session save to complete before writing the header. Since `express-session` *already* short-circuits when there's no modified session data to save, a patch in `express-session` for redirects would not incur a performance penalty.\r\n\r\n> especially since you currently can strategically place the force saves.\r\n\r\nThat's a workaround, not a fix."}}
{"actor":{"display_login":"joepie91"}}