Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ZMQ_HEARTBEAT_TTL maximum value check #3135

Merged
merged 3 commits into from
May 25, 2018

Conversation

sigiesec
Copy link
Member

@sigiesec sigiesec commented May 25, 2018

@@ -665,8 +667,8 @@ int zmq::options_t::setsockopt (int option_,

case ZMQ_HEARTBEAT_TTL:
// Convert this to deciseconds from milliseconds
value = value / 100;
if (is_int && value >= 0 && value <= 6553) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this was a typo? Right now the max TTL is one hour and a half, this would make it 18 hours which is a bit much

https://rfc.zeromq.org/spec:37/ZMTP

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok... that's really in the spec... But it is a very strange value, isn't it? ;)

Anyway, I will change it back to the previous value, but it makes sense to add the tests, so I keep the PR open and fix.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's very very strange :-)

The spec is in DRAFT form, so feel free to amend it to something less strange if you want to

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I checked it again... and now I understand, but it is even a bit weirder:

First, the spec says:

The ping-ttl is a 16-bit unsigned integer in network order that MAY be zero or MAY contain a time-to-live measured in tenths of seconds

This would allow values up to UINT16_MAX==65535 deciseconds, as my PR implements.

Then it says:

The maximum TTL is 6553 seconds

This would allow values up to 65530 deciseconds

So UINT16_MAX is almost correct according to the spec, in fact it were UINT16_MAX - UINT16_MAX % 10.

However, I think this second sentence is not meant to restrict the value, but simply explain the consequence of having a 16 bit unsigned integer specifying deciseconds.

Maybe the wording in the spec should be changed to:

As a consequence, the maximum TTL is 6553.5 seconds

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, that makes even more sense, feel free to send a pr to the rfc and I'll merge that too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will also add this to doc/zmq_setsockopt.txt

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@sigiesec sigiesec force-pushed the fix-heartbeat-ttl-max branch from c16c331 to c7632be Compare May 25, 2018 13:06
@@ -366,6 +374,49 @@ DEFINE_TESTS (pull, push, ZMQ_PULL, ZMQ_PUSH)
DEFINE_TESTS (sub, pub, ZMQ_SUB, ZMQ_PUB)
DEFINE_TESTS (pair, pair, ZMQ_PAIR, ZMQ_PAIR)

const int deciseconds_per_millisecond = 100;
// TODO the maximum value is not documented, should it?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the TODO can go now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, removed it

@sigiesec sigiesec force-pushed the fix-heartbeat-ttl-max branch from c7632be to 7637609 Compare May 25, 2018 13:12
@bluca bluca merged commit 79d5ac3 into zeromq:master May 25, 2018
@sigiesec sigiesec deleted the fix-heartbeat-ttl-max branch May 25, 2018 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants