Skip to content

Ignore already sent responses#248

Closed
SteffenDE wants to merge 1 commit into
mainfrom
sd-ignore-already-sent
Closed

Ignore already sent responses#248
SteffenDE wants to merge 1 commit into
mainfrom
sd-ignore-already-sent

Conversation

@SteffenDE

Copy link
Copy Markdown
Collaborator

Closes #247.

Since Plug does not expose the full status list of what is considered already sent, rescuing is cleanest, I think.

@josevalim

Copy link
Copy Markdown
Contributor

We should be able to check for the conn.state accordingly, no? We will also need a new release

@josevalim

Copy link
Copy Markdown
Contributor

Wait, this is a bug in plug perhaps

@SteffenDE

Copy link
Copy Markdown
Collaborator Author

Plug uses

@unsent [:unset, :set, :set_chunked, :set_file]

to determine when to raise already sent, so yes we could check conn.state, but then we'd duplicate that logic.

For the websock upgrade, the state is :upgraded.

@josevalim

Copy link
Copy Markdown
Contributor

Yeah, this is a bug in Plug. We added run_before_send(conn, :upgraded) but it is running after set. We should do run_before_send(conn, :set_upgrade) and then update it for upgraded.

@SteffenDE

Copy link
Copy Markdown
Collaborator Author

I also found phoenixframework/phoenix#6741, which might also be solved on the Plug side? I think conn.status should be 101 after upgrade, but right now it is nil.

@SteffenDE

Copy link
Copy Markdown
Collaborator Author

elixir-plug/plug#1320

@SteffenDE

Copy link
Copy Markdown
Collaborator Author

Closing in favor of upstream fix!

@SteffenDE SteffenDE closed this Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

before_send callback crashes with AlreadySentError on WebSocket upgrades

2 participants