mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2026-11-25 13:11:36 +00:00
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:
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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`
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -209,8 +209,13 @@ class Socket final : public fair::mq::Socket
|
||||
}
|
||||
int elapsed = 0;
|
||||
|
||||
// meta msg format: | n | MetaHeader 1 | ... | MetaHeader n | padded to fMetadataMsgSize |
|
||||
auto const n = msgVec.size();
|
||||
if (n == 0) { // same as the zeromq transport
|
||||
LOG(warn) << "Will not send empty vector";
|
||||
return static_cast<int>(TransferCode::error);
|
||||
}
|
||||
|
||||
// meta msg format: | n | MetaHeader 1 | ... | MetaHeader n | padded to fMetadataMsgSize |
|
||||
zmq::ZMsg zmqMsg(std::max(fMetadataMsgSize, sizeof(std::size_t) + n * sizeof(MetaHeader)));
|
||||
|
||||
auto meta_n = static_cast<std::size_t*>(zmqMsg.Data());
|
||||
|
||||
@@ -118,11 +118,8 @@ TEST_P(PartsTransfer, EmptyAndNonEmpty)
|
||||
EXPECT_EQ(AsString(in[2]), "cde");
|
||||
}
|
||||
|
||||
// Known defect: the transports do not agree on an empty Parts. zeromq refuses
|
||||
// it (TransferCode::error). shmem sends a message with zero parts, returns 0,
|
||||
// and the receiver gets a Receive() with zero parts. Enable this test when
|
||||
// both transports have the same behavior.
|
||||
TEST_P(PartsTransfer, DISABLED_EmptyPartsIsRefused)
|
||||
// All transports refuse to send an empty Parts.
|
||||
TEST_P(PartsTransfer, EmptyPartsIsRefused)
|
||||
{
|
||||
ProgOptions config;
|
||||
test::Configure(config, tools::Uuid(), GetParam().expandedShmMetadata);
|
||||
|
||||
Reference in New Issue
Block a user