Skip to content

Any software design issues #2555

Closed
Closed

Description

@jankos-night

Issue Description

Hi, may I ask why when new reset context, it set all properties to nil except for http.Request and http.ResponseWriter? What would be the problem if the implementation is the same as method NewContext?

Activity

  1. aldas commented on Dec 5, 2023

    @aldas
    Contributor

    echo.context is reused for http requests and between each request we need to reset it so there would not be data leaking from one request to other. We avoid using NewContext as much as possible to avoid allocating memory.

    This happens here:

    echo/echo.go

    Lines 648 to 652 in 584cb85

    func (e *Echo) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    // Acquire context
    c := e.pool.Get().(*context)
    c.Reset(r, w)
    var h HandlerFunc

    and at the end of ServeHTTP that context is put back to pool to be used for another request.

  2. locked and limited conversation to collaborators on Dec 5, 2023
  3. converted this issue into a discussion #2556 on Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions