[
https://issues.apache.org/jira/browse/ZOOKEEPER-1485?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15303532#comment-15303532
]
Marshall McMullen commented on ZOOKEEPER-1485:
----------------------------------------------
I think that [~makuchta] is right on this one as well. If he's right, and the
only purpose of the C client xid is to to track equality of operations
submitted to the server and the responses that come back, then it seems like
the simplest, and most correct thing to do here is the following:
1. In get_xid(), we should initialize xid to 0 rather than time(0). Starting at
zero instead of the time since the epoch ensures we have as much runway as
possible before we wrap.
2. As Martin suggests, Inside get_xid, if we overflow INT32_MAX, then simply
set it back to 0. I don't think there's any risk of collisions here since that
gives us as the maximum amount of digits before wrapping. The odds of an
existing in-flight operation that happened 2147483647 operations ago still
lingering around or causing any confusion seems beyond unlikely IMO.
The nice thing about this is we don't have to make any changes to the server or
worry about compatibility.
[~phunt] what do you think?
> client xid overflow is not handled
> ----------------------------------
>
> Key: ZOOKEEPER-1485
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-1485
> Project: ZooKeeper
> Issue Type: Bug
> Components: c client, java client
> Affects Versions: 3.4.3, 3.3.5
> Reporter: Michi Mutsuzaki
> Assignee: Bruce Gao
>
> Both Java and C clients use signed 32-bit int as XIDs. XIDs are assumed to be
> non-negative, and zookeeper uses some negative values as special XIDs (e.g.
> -2 for ping, -4 for auth). However, neither Java nor C client ensures the
> XIDs it generates are non-negative, and the server doesn't reject negative
> XIDs.
> Pat had some suggestions on how to fix this:
> - (bin-compat) Expire the session when the client sends a negative XID.
> - (bin-incompat) In addition to expiring the session, use 64-bit int for XID
> so that overflow will practically never happen.
> --Michi
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)