Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [Bug]: Otelfiber blocks stream writers #1126

Open
3 tasks done
RohanDoshi21 opened this issue Jun 7, 2024 · 1 comment
Open
3 tasks done

🐛 [Bug]: Otelfiber blocks stream writers #1126

RohanDoshi21 opened this issue Jun 7, 2024 · 1 comment
Labels
☢️ Bug Something isn't working

Comments

@RohanDoshi21
Copy link

Bug Description

The stream writer is attempting to flush events, but the initial response is never received on the client, neither are the subsequent events.

How to Reproduce

Steps to reproduce the behavior:

  1. Use go-fiber recipe example Link
  2. Add otel-fiber middleware to this example
  3. Immediately the requests gets blocked
    get

Expected Behavior

Otelfiber shouldn't block stream writers.

Contrib package Version

v1.0.10

Code Snippet (optional)

package main

import (
	"bufio"
	"fmt"
	"log"
	"time"

	"github.com/gofiber/contrib/otelfiber"
	"github.com/gofiber/fiber/v2"
	"github.com/gofiber/fiber/v2/middleware/cors"
	"github.com/valyala/fasthttp"
)

func main() {
	// Fiber instance
	app := fiber.New()

	// CORS for external resources
	app.Use(cors.New(cors.Config{
		AllowOrigins: "*",
		AllowHeaders: "Cache-Control",
	}))

	app.Use(otelfiber.Middleware(
		otelfiber.WithServerName("test"),
	))

	app.Get("/sse", func(c *fiber.Ctx) error {
		c.Set("Content-Type", "text/event-stream")
		c.Set("Cache-Control", "no-cache")
		c.Set("Connection", "keep-alive")
		c.Set("Transfer-Encoding", "chunked")

		c.Context().SetBodyStreamWriter(fasthttp.StreamWriter(func(w *bufio.Writer) {
			fmt.Println("WRITER")
			var i int
			for {
				i++
				msg := fmt.Sprintf("%d - the time is %v", i, time.Now())
				fmt.Fprintf(w, "data: Message: %s\n\n", msg)
				fmt.Println(msg)

				w.Flush()
				time.Sleep(5 * time.Second)
			}
		}))

		return nil
	})

	// Start server
	log.Fatal(app.Listen(":3000"))
}

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my problem prior to opening this one.
  • I understand that improperly formatted bug reports may be closed without explanation.
@RohanDoshi21 RohanDoshi21 added the ☢️ Bug Something isn't working label Jun 7, 2024
@chenxi393
Copy link

I also encountered this problem. How can I solve this problem while using otel-fiber?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
☢️ Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants