Skip to content

FastQueue has incorrect capacity handling for positive and zero maxSize values #203

Description

@yingying9025123-code
  `FastQueue.put_nowait()` has an off-by-one capacity check and incorrect
  handling of `maxSize=0`.

  Current code in `pysyncobj/fast_queue.py`:

  ```python
  if len(self.__queue) > self.__maxSize:
      raise Queue.Full()

Because the condition is checked before appending:

  • FastQueue(1) accepts two items, and only rejects the third;
  • FastQueue(0) accepts one item, then rejects the second.

Minimal reproducer:

  import queue
  from pysyncobj.fast_queue import FastQueue

  for max_size in (1, 0):
      q = FastQueue(max_size)
      q.put_nowait("first")
      try:
          q.put_nowait("second")
          print(f"FastQueue({max_size}): second item accepted")
      except queue.Full:
          print(f"FastQueue({max_size}): second item rejected")

Actual output:

  FastQueue(1): second item accepted
  FastQueue(0): second item rejected

Expected behavior:

  • For FastQueue(1), the second item should raise queue.Full.
  • SyncObjConf.validate() accepts commandsQueueSize=0, and SyncObj
    passes it directly to FastQueue. Following the standard Python
    queue.Queue(maxsize=0) convention, zero should mean an unbounded queue,
    so multiple items should be accepted.

Suggested fix:

  if self.__maxSize > 0 and len(self.__queue) >= self.__maxSize:
      raise Queue.Full()

This is confirmed on the current upstream master source.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions