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

jwt-proxy doesn't work with SSE (Server Side Events) #15942

Closed
ChristianSchenk711 opened this issue Feb 5, 2020 · 3 comments
Closed

jwt-proxy doesn't work with SSE (Server Side Events) #15942

ChristianSchenk711 opened this issue Feb 5, 2020 · 3 comments
Labels
kind/bug Outline of a bug - must adhere to the bug report template. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. severity/P1 Has a major impact to usage or development of the system.

Comments

@ChristianSchenk711
Copy link

I have added and deployed some extra plugins for theia. One of those plugins uses SSE (Server Side Events) events to get notifications. However that did work locally but not after deploying this to our cluster.

I figured out that the problem for me was the jwt-proxy:

SSE works such, that the server writes a few lines to a long-polling HTTP GET whenever it wants to notify the client. However the jwt-proxy will not flush these lines and therefore they will get buffered until the buffer used by io.copy is used is full (which seems to be in the range of 8-16KB which equals to a lot of messages...)

For testing I used a simple SSE Server (like this: https://jasonbutz.info/2018/08/server-sent-events-with-node/) which sents a message every second to subscribers.
If I try to connect to this source behind the jwt-proxy, it will return the messages as bunch, which makes it quite pointless.

I would suggest to handle SSE with an explicit Flush, e.g. like that in proxy.go:

	var finalWriter io.Writer = w
		if w.Header().Get("content-type") == "text/event-stream" {
			finalWriter = NewFlushWriter(w)
		}
		nr, err := io.Copy(finalWriter, resp.Body)

The FlushWriter would just overwrite "write" and call a flush afterwards:


type FlushWriter struct {
	w      io.Writer
	writes uint64
	bytes  uint64
}

func NewFlushWriter(w io.Writer) *FlushWriter {
	return &FlushWriter{w: w}
}

func (w *FlushWriter) Write(b []byte) (int, error) {
	a, err := w.w.Write(b)
	if f, ok := w.w.(http.Flusher); ok {
		f.Flush()
	} else {
		log.Fatal("no flush")
	}
	return a, err
}

With these modifications the simple SSE example properly returns one message per second.

@ChristianSchenk711 ChristianSchenk711 added the kind/bug Outline of a bug - must adhere to the bug report template. label Feb 5, 2020
@che-bot che-bot added the status/need-triage An issue that needs to be prioritized by the curator responsible for the triage. See https://github. label Feb 5, 2020
@benoitf benoitf added area/jwt-proxy severity/P1 Has a major impact to usage or development of the system. and removed status/need-triage An issue that needs to be prioritized by the curator responsible for the triage. See https://github. labels Feb 5, 2020
@ChristianSchenk711
Copy link
Author

Just realized, that this actually is a problem of the vendored underlying coreos/goproxy in
vendor/github.com/coreos/goproxy/proxy.go, not in proxy/proxy.go So I probably will open a ticket there as well, since that fix needs to go into coreos/goproxy/proxy.go

@ChristianSchenk711
Copy link
Author

Reported to coreos/goproxy: coreos/goproxy#5

@che-bot
Copy link
Contributor

che-bot commented Aug 21, 2020

Issues go stale after 180 days of inactivity. lifecycle/stale issues rot after an additional 7 days of inactivity and eventually close.

Mark the issue as fresh with /remove-lifecycle stale in a new comment.

If this issue is safe to close now please do so.

Moderators: Add lifecycle/frozen label to avoid stale mode.

@che-bot che-bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Aug 21, 2020
@che-bot che-bot closed this as completed Sep 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Outline of a bug - must adhere to the bug report template. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. severity/P1 Has a major impact to usage or development of the system.
Projects
None yet
Development

No branches or pull requests

3 participants