gofiber / utils

:zap: A collection of common functions but with better performance, less allocations and less dependencies created for Fiber.
https://gofiber.github.io/utils/
MIT License
48 stars 10 forks source link

🚀 [Feature]: Allow to stop the timestamp updater #69

Open leonklingele opened 9 months ago

leonklingele commented 9 months ago

Feature Description

There should be a way to stop the timestamp updater again so we don't leak a goroutine.

When using Uber's goleak you have to manually ignore these after shutting down the fiber server:

package handlers_test

import (
    "testing"

    "go.uber.org/goleak"
)

func TestMain(m *testing.M) {
    goleak.VerifyTestMain(
        m,
        // TODO: Fix those leaks upstream
        goleak.IgnoreTopFunction("time.Sleep"), // https://github.com/valyala/fasthttp/blob/0be5a4150cb0e35605cffd09e922707355dbdec3/fs.go#L477-L480
        goleak.IgnoreTopFunction("github.com/gofiber/fiber/v2/internal/memory.(*Storage).gc"),
        goleak.IgnoreTopFunction("github.com/gofiber/fiber/v2/internal/storage/memory.(*Storage).gc"),
        goleak.IgnoreTopFunction("github.com/gofiber/fiber/v2/internal/storage/memory.New.StartTimeStampUpdater.func1.1"),
        goleak.IgnoreTopFunction("github.com/gofiber/fiber/v2/utils.StartTimeStampUpdater.func1.1"),
    )
}

Additional Context (optional)

No response

Code Snippet (optional)

No response

Checklist:

ReneWerner87 commented 9 months ago

this concept was copied from fasthttp and is supposed to bring performance what is the alternative without the loss of performance ?

leonklingele commented 9 months ago

Just provide another function which stops the timer once started. This func should be called by whoever has started the timer after e.g. the fiber server was stopped.

nickajacks1 commented 9 months ago

this concept was copied from fasthttp and is supposed to bring performance what is the alternative without the loss of performance ?

This isnt proposing to get rid of the timer, just adding the ability to shut it down manually.

ReneWerner87 commented 9 months ago

Ok, sorry misunderstanding Then sure we could do it