Skip to content

Instantly run task after write operation - #1528

Open
Beaness wants to merge 4 commits into
retrooper:2.0from
Beaness:instanttask
Open

Instantly run task after write operation#1528
Beaness wants to merge 4 commits into
retrooper:2.0from
Beaness:instanttask

Conversation

@Beaness

@Beaness Beaness commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Once again #1460

Right now it's possible other packets get written before the promise is completed, If you want to write a packet right after another packet using getTasksAfterSend it's possible another packet gets written inbetween. This solves it for spigot (sponge needs a different type of implementation, probably overwriting the whole write function to execute the tasks).

However this seems to have caused issues

@Axionize (packetevents discord):
GrimAnticheat/Grim#2589
GrimAnticheat/Grim#2588
GrimAnticheat/Grim#2587
GrimAnticheat/Grim#2586
GrimAnticheat/Grim#2586
BadpacketsN also starts flagging
amongst many otherthings

Marked as draft until the issues have been fixed

booky10 added 4 commits June 2, 2026 15:03
This was used previously while we still relied on netty's built-in MessageToMessageEncoder, which didn't allow to have proper "tasks-after-send"
We really need to refactor these copy-pasted handlers into a common module...
Why does this list of runnables only exist for clientbound packets? Doesn't make sense to me
@Beaness
Beaness marked this pull request as draft June 2, 2026 13:12
@Beaness
Beaness marked this pull request as ready for review June 2, 2026 14:54
@Beaness

Beaness commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

No longer marked as draft, after further analysis it seems to be that the merge commit with Grim PacketEvents had inverted preVIa (GrimAnticheat@2f4163f#diff-3167a052813eba4c51f921f2e6d380977bd1de679ffb6e0bb62a1897d8c2c0bf)
Also the implementation of this w/ preVia requires extra logic to persist task order

tail
    -> normal PacketEvents   // sees packet first, registers/runs normal task
    -> ViaVersion
    -> preVia PacketEvents   // sees packet second, registers/runs preVia task
    -> head/socket

  Before PR:

  normal PE sees A       // adds normal task to promise first
  preVia PE sees A       // adds preVia task to same promise second
  promise completes
  normal task runs       // first registered
  preVia task runs       // second registered

  After PR:

  normal PE sees A
  normal PE calls ctx.write(A)
    -> ViaVersion
    -> preVia PE sees A
    -> preVia PE calls ctx.write(A)
    -> preVia task runs     // runs while nested inside normal ctx.write(A)
  normal task runs          // runs after ctx.write(A) returns to normal PE

A solution for this would be by instead of running the post tasks in preVia it adds them to a collection in normal pe handler so that order is persisted and the normal pe handler can run them after the write. But current PacketEvents does not implement preVia injection until #1446 is merged.

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.

2 participants