Message lost on 2 separate connections to same URL

Open
#147 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
php
Domain
networking

Research direction

Start with the publish method and its ratchet\client\connect calls, then reproduce the two back-to-back publishes shown in the issue. Trace why the first message is ignored when separate connections use the same URL, and verify the behavior with both messages sent independently. Done means the cause is identified and both messages are reliably delivered, or the limitation is documented.

Written by the indexing model from the issue text.

Description

Using ratchet/pawl v0.4.1 and PHP 7.4

Implemented pub/sub client in PHP...

public function publish(string $user, string $group, string $message)
    {
        $hubUrl = $this->getHubUrl();
        $accessToken = $this->getAccessToken($user);
        $url = $hubUrl.'?access_token='.$accessToken;
        $this->user = $user;
        $this->group = $group;
        $this->message = $message;
        \ratchet\client\connect($url,['json.webpubsub.azure.v1'])->then(function($conn) {
            $sendMessage = [
                'type' => 'sendToGroup',
                'group' => $this->group,
                'data' => [
                    'message' => $this->message
                ]
            ];
            $sendMessageText = json_encode($sendMessage);

            $joingroup = [
                "type" => "joinGroup",
                "group" => $this->group
            ];            
            $joingroupText = json_encode($joingroup);
            $conn->send($joingroupText);
            $conn->send($sendMessageText);
            $conn->close();
        }, function ($e) {
            error_log("Could not connect: {$e->getMessage()}\n");
        });        
    }

This works great. However, if I send back-to-back messages, e.g.

    $pubSubService->publish('server','activity-queue',json_encode($queueEntry));
    $pubSubService->publish('server','agent-table',json_encode($agent));

The first message is always lost. I've fixed this by queuing up the messages to the same URL and sending them together on the same connection. A much better design, I admit.

At the same time, this should work. Why do back-to-back messages on separate connections to the same URL fail? It took me quite a while to find this. There are no error messages. The first messages is simply ignored.

Dominant language
PHP
Stars
616
Forks
98
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ratchetphp/Pawl

All issues in ratchetphp/Pawl

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.