Skip to content

Channel.push may cause Push's ref be generated twice #4948

Closed

Description

@xh4

Environment

  • Elixir version (elixir -v): 1.12.3
  • Phoenix version (mix deps): 1.6.11
  • Operating system: Windows 11

Expected behavior

A push's ref should not change unless the push was resend.

Actual behavior

When invoke channel.push and when channel.canPush() returns false, the push will be put in channel's pushBuffer,

if(this.canPush()){
  pushEvent.send()
} else {
  pushEvent.startTimeout()
  this.pushBuffer.push(pushEvent)
}

Later when the channel joined, pushes in pushBuffer will invoke the send method which invoke the startTimeout method.

The problem is startTimeout will be called twice on a push if the channel can not push immediately, cause the ref in buffered push be re-generated. And of course the corresponding refEvent timeoutTimer become useless.

startTimeout(){
    if(this.timeoutTimer){ this.cancelTimeout() }
    this.ref = this.channel.socket.makeRef()
    this.refEvent = this.channel.replyEventName(this.ref)

    this.channel.on(this.refEvent, payload => {
      this.cancelRefEvent()
      this.cancelTimeout()
      this.receivedResp = payload
      this.matchReceive(payload)
    })

    this.timeoutTimer = setTimeout(() => {
      this.trigger("timeout", {})
    }, this.timeout)
}

Maybe we should use the resend method instead of send on buffered push.

Activity

  1. self-assigned this
    on Dec 12, 2022
  2. chrismccord commented on Jan 6, 2023

    @chrismccord
    Member

    A ref being generated and not used isn't a problem as far as I can tell. Can you confirm you are seeing a bug associated when regenerating the ref? If the only issue is discarding an unsent ref, then I don't consider that an issue. If you think there is still a bug present with acknowledgement handling or timeouts please let me know. Thanks!

  3. Gazler commented on Sep 12, 2023

    @Gazler
    Member

    Closing due to no response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions