fix(shmem): refuse to send an empty Parts

- zeromq refuses an empty Parts with TransferCode::error; shmem sent a
  message with zero parts and returned 0, and the receiver got a
  Receive() with zero parts
- Refuse it in shmem too, with the same warning
- Enable PartsTransfer.EmptyPartsIsRefused
- Update the documentation pages that described the defect, and
  the source line links into the changed files

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Claude
2026-11-04 20:32:00 +00:00
committed by Dennis Klein
parent 50387fe5cc
commit 102cdaf40e
7 changed files with 14 additions and 16 deletions

View File

@@ -182,7 +182,7 @@ Each socket counts its transfers. [`Channel`](/api/fair/mq/Channel/) gives the c
| [`GetMessagesRx()`](/api/fair/mq/Channel/#GetMessagesRx) | Messages that `Receive()` got. |
| [`GetBytesRx()`](/api/fair/mq/Channel/#GetBytesRx) | Bytes of these messages. |
The rules are in the send and receive functions of the transports ([zeromq/Socket.h](/source/fairmq/zeromq/Socket.h/#L96-L255), [shmem/Socket.h](/source/fairmq/shmem/Socket.h/#L118-L315)):
The rules are in the send and receive functions of the transports ([zeromq/Socket.h](/source/fairmq/zeromq/Socket.h/#L96-L255), [shmem/Socket.h](/source/fairmq/shmem/Socket.h/#L118-L320)):
- The counters start at 0 when the transport makes the socket. In a device, this occurs in `BINDING` or `CONNECTING`. After `RESET DEVICE`, the next initialization makes new sockets, which start at 0 again.
- Only a successful transfer counts. A timeout, an interruption or an error does not change the counters.

View File

@@ -226,8 +226,7 @@ apply to each part. This test sends three parts, one of them empty, and receives
<Snippet file="test/parts/_access.cxx" start="Parts out(" end="EXPECT_EQ(AsString(in[2])" />
:::caution[Rules for multipart messages]
- Do not send an empty `Parts` object. The zeromq transport returns `TransferCode::error`, but the
shmem transport sends a message with zero parts.
- Do not send an empty `Parts` object. Both transports return `TransferCode::error`.
- Receive with the same form that the sender uses: `Parts` for `Parts`, `MessagePtr` for
`MessagePtr`. The shmem transport cannot read a single message into a `Parts` object.
- `Receive()` adds the received parts at the end of the `Parts` object. Give it an empty one.

View File

@@ -88,7 +88,7 @@ Some rules follow from this table:
| Subscribe and unsubscribe for state changes | Yes. A mutex protects the subscriptions. | [StateMachine.cxx](/source/fairmq/StateMachine.cxx/#L318-L335), test `PluginServices.SubscriptionThreadSafety` |
| [`WaitForState()`](/api/fair/mq/Device/#WaitForState), [`WaitForNextState()`](/api/fair/mq/Device/#WaitForNextState) | Call them from one thread only. The queue of states gives each state to one caller. | [StateQueue.h](/source/fairmq/StateQueue.h/#L31-L35) |
| [`Interrupt()`](/api/fair/mq/TransportFactory/#Interrupt), [`Resume()`](/api/fair/mq/TransportFactory/#Resume) of a transport | Yes. They set an atomic flag. | [zeromq/Context.h](/source/fairmq/zeromq/Context.h/#L149-L150), [shmem/Manager.h](/source/fairmq/shmem/Manager.h/#L283-L284), test `InterruptTransfer.Receive` |
| The byte and message counters of a channel, for example [`GetBytesTx()`](/api/fair/mq/Channel/#GetBytesTx) | Yes. The sockets keep them in atomic values. The rate logger thread reads them. | [zeromq/Socket.h](/source/fairmq/zeromq/Socket.h/#L399-L402), [shmem/Socket.h](/source/fairmq/shmem/Socket.h/#L459-L462) |
| The byte and message counters of a channel, for example [`GetBytesTx()`](/api/fair/mq/Channel/#GetBytesTx) | Yes. The sockets keep them in atomic values. The rate logger thread reads them. | [zeromq/Socket.h](/source/fairmq/zeromq/Socket.h/#L399-L402), [shmem/Socket.h](/source/fairmq/shmem/Socket.h/#L464-L467) |
The device makes its channels in `INITIALIZING DEVICE`, after `Init()`
([Device.cxx](/source/fairmq/Device.cxx/#L153-L171)). It removes them in `RESETTING DEVICE`

View File

@@ -118,7 +118,7 @@ A poller and the data callbacks of `OnData()` use the transport of sub-channel 0
### `sndBufSize` and `rcvBufSize`
The maximum number of messages in the send queue and in the receive queue of the socket. They are the ZeroMQ high-water marks `ZMQ_SNDHWM` and `ZMQ_RCVHWM` ([zeromq/Socket.h](/source/fairmq/zeromq/Socket.h/#L310-L332)). The `shmem` transport sets the same options on its ZeroMQ socket, which carries the metadata of the messages ([shmem/Socket.h](/source/fairmq/shmem/Socket.h/#L370-L392)). For ZeroMQ, 0 means no limit. A negative value makes `Validate()` throw `ChannelConfigurationError`.
The maximum number of messages in the send queue and in the receive queue of the socket. They are the ZeroMQ high-water marks `ZMQ_SNDHWM` and `ZMQ_RCVHWM` ([zeromq/Socket.h](/source/fairmq/zeromq/Socket.h/#L310-L332)). The `shmem` transport sets the same options on its ZeroMQ socket, which carries the metadata of the messages ([shmem/Socket.h](/source/fairmq/shmem/Socket.h/#L375-L397)). For ZeroMQ, 0 means no limit. A negative value makes `Validate()` throw `ChannelConfigurationError`.
The behavior of a socket with a full queue depends on the socket type. The ZeroMQ documentation of `zmq_socket` describes it.

View File

@@ -47,11 +47,8 @@ default is `-1` ([`Channel.h`](/source/fairmq/Channel.h/#L376-L377)). The steps
the internal socket timeout of the zeromq and shmem transports
([`zeromq/Common.h`](/source/fairmq/zeromq/Common.h/#L64-L77)).
:::caution[Known defect]
The transports do not agree on an empty `Parts`. zeromq logs `Will not send empty vector` and returns
`error`. shmem sends a message with zero parts and returns 0. See the disabled test
`PartsTransfer.EmptyPartsIsRefused` in `test/parts/_access.cxx`.
:::
Both transports refuse to send an empty `Parts`. They log `Will not send empty vector` and return
`error`. The test `PartsTransfer.EmptyPartsIsRefused` in `test/parts/_access.cxx` checks this.
## Error codes