Demo relay drops the final Object when PUBLISH_DONE arrives first

Open
#52 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
42/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c, python
Domain
networking

Research direction

Start in the draft-22 demo relay where imquic_demo_publish_done removes the track and its alias lookup, and compare that teardown with when imquic_demo_incoming_object can still receive the final upstream object. Run the supplied repro.py against a restartable imquic-moq-relay, first without delay and then with --delay-ms 100, and read relay.log around the "Removing track" and "No track found" lines. Done means the subscriber receives all 120 objects, four stream endings and PUBLISH_DONE without the delay.

Written by the indexing model from the issue text.

Description

With imquic main at d93d181, the
raw-QUIC draft-22 demo relay can receive PUBLISH_DONE before the final
Object callback. It removes the track, then cannot forward that Object.

The reproducer sends 120 Objects on four subgroup streams. In failing
runs the Subscriber receives 119 Objects, missing Group 3/Object 29,
although it receives four stream endings and PUBLISH_DONE.

The relay logs:

[moq-relay/1] Subscription via ID 1 is done, using 4 streams: status 2 (track ended)
Removing track 'track'
[moq-relay/1] Incoming object: reqid=0, alias=0, group=3, subgroup=0 (first=1), id=29, priority=128 (set), payload=8192 bytes, properties=0, delivery=STREAM_HEADER_SUBGROUP, status=NORMAL_OBJECT, eos=1
[WARN] [moq-relay/1] No track found for that subscription

imquic_demo_publish_done removes the track and its alias lookup before
imquic_demo_incoming_object handles the final Object. Could teardown
wait for the outstanding upstream stream data? Adding 100 ms before
sending PUBLISH_DONE avoided the failure in the tested runs.

Reproduce

Linux x86_64, Python 3.13, and a built imquic-moq-relay are required.
The tested relay used picoquic f506de8 and picotls e446233.
Save the Python code below as repro.py, then run:

python3 -m venv .venv
.venv/bin/pip install aiomoqt==0.14.1 aiopquic==0.7.1
openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -noenc \
  -days 1 -subj /CN=localhost -addext subjectAltName=IP:127.0.0.1 \
  -keyout key.pem -out cert.pem
imquic-moq-relay -b 127.0.0.1 -p 45447 -M 22 -q -d 4 \
  -c cert.pem -k key.pem > relay.log 2>&1 &
relay_pid=$!
.venv/bin/python repro.py --cert cert.pem
kill "$relay_pid"
wait "$relay_pid"

Restart the relay for each attempt and repeat, since callback ordering
varies. Compare with repro.py --cert cert.pem --delay-ms 100.
The Python code uses test helpers from the pinned aiomoqt package.

repro.py
"""Reproduce draft-22 demo-relay terminal Object loss on loopback."""

import argparse
import asyncio
import logging

from aiomoqt.client import MOQTClient
from aiomoqt.tools.moq_interop_client import _DataPublisher, _DataSubscriber, _is_normal
from aiomoqt.track import SubscribedTrack
from aiomoqt.types import GroupOrder, MOQTMessageType

# 4 groups, 30 Objects/group, 8192-byte payloads, 20 ms pacing.
CASE = ("moq-test-00", "0", "0", "0", "3", "29", "30", "8192", "8192",
        "20", "1", "1", "0", "-1", "-1", "0")
NAMESPACE = "moq-test/terminal-repro"


class Receiver(_DataSubscriber):
    def __init__(self):
        super().__init__()
        self.seen = set()
        self.errors = 0

    def on_object(self, msg, size, ts, group_id, subgroup_id):
        if not _is_normal(getattr(msg, "status", None)):
            return
        location = group_id, msg.object_id
        if location in self.seen or subgroup_id != 0 or bytes(msg.payload) != b"t" * 8192:
            self.errors += 1
        self.seen.add(location)


async def run(args):
    publisher = _DataPublisher(tuple(part.encode() for part in NAMESPACE.split("/")), b"track")
    receiver = Receiver()
    pub = MOQTClient("127.0.0.1", args.port, use_quic=True, ca_file=args.cert,
                     supported_drafts=22)
    sub = MOQTClient("127.0.0.1", args.port, use_quic=True, ca_file=args.cert,
                     supported_drafts=22)
    pub.register_handler(MOQTMessageType.SUBSCRIBE, publisher.on_subscribe)
    async with asyncio.timeout(20):
        async with pub.connect() as ps:
            await ps.client_session_init()
            await ps.publish_namespace(namespace=NAMESPACE, wait_response=True)
            async with sub.connect() as ss:
                await ss.client_session_init()
                assert ps.negotiated_draft == ss.negotiated_draft == 22
                track = SubscribedTrack(ss, "/".join((NAMESPACE, *CASE)), "track",
                                        on_object=receiver.on_object, on_done=receiver.on_done)
                await track.subscribe(forward=None, group_order=GroupOrder.ASCENDING)
                ss.register_stream_end_handler(track.track_alias, receiver.on_stream_end)
                await publisher.subscribed.wait()
                await asyncio.sleep(1)
                # Intercept only the terminal control send, keeping data/FIN unchanged.
                original = ps.subscribe_done
                pending = []
                ps.subscribe_done = lambda **fields: pending.append(fields)
                try:
                    await publisher.send(ps)
                finally:
                    ps.subscribe_done = original
                if len(pending) != 1:
                    raise RuntimeError("Expected one PUBLISH_DONE")
                if args.delay_ms:
                    await asyncio.sleep(args.delay_ms / 1000)
                original(**pending[0])
                await receiver.drain(asyncio.get_running_loop().time() + 7)
                expected = {(g, o) for g in range(4) for o in range(30)}
                missing = sorted(expected - receiver.seen)
                print(f"received={len(receiver.seen)}/120 missing={missing} "
                      f"streams={receiver.streams_ended} done={receiver.done is not None} "
                      f"payload_errors={receiver.errors}")
                if (receiver.seen != expected or receiver.errors or receiver.streams_reset
                        or receiver.streams_ended != 4 or receiver.done is None):
                    raise SystemExit(1)


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--cert", required=True, help="Trusted loopback relay certificate")
    parser.add_argument("--port", type=int, default=45447)
    parser.add_argument("--delay-ms", type=int, choices=(0, 100), default=0)
    args = parser.parse_args()
    logging.disable(logging.INFO)
    asyncio.run(run(args))

The FIN/framing fix for #44
is present in this commit. Here the final Object reaches the relay after
track removal. A similar termination-ordering problem was fixed in
MOQtail #382.

I suspect this may differ from the intended termination behavior in IETF MoQT draft-22, but I may be misreading the draft. Could you confirm whether this behavior is expected?

AI assistance was used to prepare the reproducer, analyze the logs, and translate the contents.

Dominant language
C
Stars
84
Forks
17
Avg merge
2h 9m
Merged PRs (30d)
1

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

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 meetecho/imquic

All issues in meetecho/imquic

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.