Skip to content

Use request's standard context instead of Gorilla's context. - #139

Closed
chea1505 wants to merge 1 commit into
gorilla:masterfrom
chea1505:master
Closed

chea1505 wants to merge 1 commit into
gorilla:masterfrom
chea1505:master

Conversation

@chea1505

@chea1505 chea1505 commented Jan 4, 2018

Copy link
Copy Markdown

Use request's standard context (context.Context) instead of Gorillar's Context. You DON'T need to wrap your handlers with Gorillar context.ClearHandler(). There is no memory leak.

Use request's standard context (context.Context) instead of Gorillar's Context. You DON'T need to wrap your handlers with Gorillar context.ClearHandler(). There is no memory leak.

@elithrar elithrar left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate the PR, but one of the reasons we've struggled with making this change sooner is that it's extremely API breaking: there's an extensive discussion in #80 surrounding this. I've deliberated over this for a long while and it's been pretty frustrating.

Critically, the major challenges are because Go doesn't have a great versioning story. golang/dep is great, but not widely used yet, and gorilla/sessions has a lot of existing users and dependent libraries that don't pin versions.

In order of priorities:

  • Not breaking the Store interface is of utmost importance. It's far reaching, and requires multiple authors working together to get that right. Some Stores aren't actively maintained, and work today. We can submit PRs to many stores to get them working, but those stores then ALSO need to version. I think we can achieve this by still keeping the Save signature the same, and just ignoring the *http.Request under the new context.

  • Not breaking the rest of the API, which is mostly the Registry (which is what handles the context stuff the most). This is harder, because you need to add *http.Request as an argument, which makes this harder: you can't 'cheat' that like you can the Store interface.

  • Not islanding Go 1.6 users, who can't use request.WithContext - I raised an issue over on gorilla/mux that describes some of the pain here.

Ideally, I had hoped that golang/dep would land in Go 1.10, which would be the catalyst for adopting versioning here. The steps after that are still non-trivial:

  1. Getting our most critical importers using dep and pinning to the old version of mux (a lot of work!)
  2. Making the breaking change with a major SemVer bump - "2.0.0" (easy, but this is where the pain comes in)
  3. Dealing with the fallout of the long tail of users who inevitably run into issues - good docs on how to address, triaging issues, etc. (ongoing)

I hope that makes sense.

Comment thread sessions.go
//
// It returns a new session if there are no sessions registered for the name.
func (s *Registry) Get(store Store, name string) (session *Session, err error) {
func (registry *Registry) Get(r *http.Request, store Store, name string) (session *Session, err error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the public API [breaking change]

Comment thread sessions.go
// the response or returning from the handler.
func (s *Session) Save(r *http.Request, w http.ResponseWriter) error {
return s.store.Save(r, w, s)
func (s *Session) Save(w http.ResponseWriter) error {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the public API [breaking change]

Comment thread store.go

// Save should persist session to the underlying store implementation.
Save(r *http.Request, w http.ResponseWriter, s *Session) error
Save(w http.ResponseWriter, s *Session) error

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the public API [breaking change]. It would break all existing store implementations, of which there are many.

Comment thread store.go
// Save adds a single session to the response.
func (s *CookieStore) Save(r *http.Request, w http.ResponseWriter,
session *Session) error {
func (s *CookieStore) Save(w http.ResponseWriter, session *Session) error {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the public API [breaking change]

@elithrar

elithrar commented Sep 3, 2018

Copy link
Copy Markdown
Contributor

As a note, I'd like to address this "soon", by:

  • Using Go Modules
  • Breaking away to a "v2" import path for the >= v2.0.0 line, as required by Modules
  • Planning out other changes to the way the Registry construct works as an intermediate cache
  • Updating securecookie at the same time, so we can break existing sessions once (we won't strive to decode existing sessions)

@elithrar elithrar changed the title Use request's standard context instead of Gorillar's context. Use request's standard context instead of Gorilla's context. Sep 14, 2018
@owais

owais commented Apr 12, 2019

Copy link
Copy Markdown

Is this waiting on Go modules to be enabled out of box in 1.13 or 1.14?

@stale

stale Bot commented Jun 30, 2019

Copy link
Copy Markdown

This issue has been automatically marked as stale because it hasn't seen a recent update. It'll be automatically closed in a few days.

@stale stale Bot added the stale label Jun 30, 2019
@stale stale Bot closed this Jul 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants