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

Missed events in the startup of the React app #19

Open
cardil opened this issue Apr 13, 2023 · 0 comments
Open

Missed events in the startup of the React app #19

cardil opened this issue Apr 13, 2023 · 0 comments
Labels
kind/bug Something isn't working

Comments

@cardil
Copy link
Member

cardil commented Apr 13, 2023

A loss of events can be observed in React component. After refresh of web browser, only the last event is being displayed:

Screenshot from 2023-04-13 17-49-28

When calling the endpoint from CLI all events are streamed:

$ http :8080/events
HTTP/1.1 200 OK
Cache-Control: no-cache
Connection: keep-alive
Content-Type: text/event-stream; charset=utf-8
Date: Thu, 13 Apr 2023 15:48:25 GMT
X-Powered-By: Express
X-SSE-Content-Type: application/cloudevents+json
transfer-encoding: chunked

data:{
    "data": {
        "a": {
            "b": "first"
        }
    },
    "datacontenttype": "application/json",
    "id": "41e1e914-bb01-41cb-83eb-5340d480c600",
    "source": "kn-event/v1.7.0",
    "specversion": "1.0",
    "time": "2023-04-13T15:45:13.216Z",
    "type": "dev.knative.cli.plugin.event.generic"
}

data:{
    "data": {
        "a": {
            "b": "second"
        }
    },
    "datacontenttype": "application/json",
    "id": "c34c0cd7-aa84-41e5-be30-cb07bea0a234",
    "source": "kn-event/v1.7.0",
    "specversion": "1.0",
    "time": "2023-04-13T15:45:19.460Z",
    "type": "dev.knative.cli.plugin.event.generic"
}

data:{
    "data": {
        "a": {
            "b": "third"
        }
    },
    "datacontenttype": "application/json",
    "id": "56141d84-01b7-46c5-bed2-13ae4761dc57",
    "source": "kn-event/v1.7.0",
    "specversion": "1.0",
    "time": "2023-04-13T15:48:21.141Z",
    "type": "dev.knative.cli.plugin.event.generic"
}
^C

I suspect this might be some kind of race in the following lines:

const sse = new EventSource(`${baseAddress}/events`, { withCredentials: true })
sse.onmessage = (e: MessageEvent) => {
const ce = new CloudEvent(JSON.parse(e.data))
this.listeners.forEach((l) => l(ce))
}

To reproduce:

  1. Deploy an app
  2. Send a few events, so you know their order (for example id==first, id==second, id=third)
  3. Open/refresh the web page

Actual result

  1. You will see just the last event being rendered

Expected result

  1. You should see all the events collected, rendered properly

/kind bug

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

No branches or pull requests

1 participant