{"record":{"id":"f7c353d5f3310973","repo":"XX-net/XX-Net","slug":"get-d-from-size-d-fail","errorCode":null,"errorMessage":"get %d from size:%d fail.","messagePattern":"get (.+?) from size:(.+?) fail\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"code/default/x_tunnel/local/base_container.py","lineNumber":191,"sourceCode":"    def wait(self, wait_order):\n        with self.lock:\n            lock = threading.Lock()\n            lock.acquire()\n\n            if len(self.waiters) == 0:\n                self.waiters.append((wait_order, lock))\n            else:\n                is_max = True\n                for i in range(0, len(self.waiters)):\n                    try:\n                        i_wait_order, ilock = self.waiters[i]\n                        if i_wait_order > wait_order:\n                            is_max = False\n                            break\n                    except Exception as e:\n                        if i >= len(self.waiters):\n                            break\n                        xlog.warn(\"get %d from size:%d fail.\", i, len(self.waiters))\n                        continue\n\n                if is_max:\n                    self.waiters.append((wait_order, lock))\n                else:\n                    self.waiters.insert(i, (wait_order, lock))\n\n        lock.acquire()\n\n    def status(self):\n        out_string = \"waiters[%d]:\\n\" % len(self.waiters)\n        for i in range(0, len(self.waiters)):\n            end_time, lock = self.waiters[i]\n            out_string += \"%d\\r\\n\" % (end_time)\n\n        return out_string\n\n","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/XX-net/XX-Net/blob/cfa5bc17b67676e467f37ec50766127e0ab5f0aa/code/default/x_tunnel/local/base_container.py#L173-L209","documentation":"While scanning the ordered waiters list to insert a lock by wait_order, an index/iteration exception occurred at position i. The loop logs and continues from the next index.","triggerScenarios":"The waiters list is mutated concurrently (another waiter inserted/removed) during iteration, causing an IndexError or comparison error on stale i; only happens when i < len(self.waiters).","commonSituations":"High-concurrency wait paths racing on the waiters list; a lock removed by its owner while another thread scans; logic changes breaking the sorted invariant.","solutions":["Review locking around waiters mutation to guarantee the scan is atomic","Recompute len(self.waiters) and validate i inside the except before continue","Consider a heap/sorted structure with proper mutex instead of manual index scanning","Reproduce under concurrency stress to confirm the race"],"exampleFix":"# before\nexcept Exception as e:\n    if i >= len(self.waiters):\n        break\n    xlog.warn(\"get %d from size:%d fail.\", i, len(self.waiters))\n    continue\n# after\nexcept Exception:\n    with self.mutex:\n        i = min(i, len(self.waiters))  # resync under lock and retry scan","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"On scan failure, resync index under the mutex and retry the scan once.","preventionTips":["Hold the same lock for scan and mutation of waiters","Use a heap keyed by wait_order to avoid manual index scanning"],"tags":["concurrency","race-condition","waiters","index"],"backgroundTag":"concurrent-modification-during-iteration","analyzedSha":"cfa5bc17b67676e467f37ec50766127e0ab5f0aa","analyzedAt":"2026-08-27T19:28:28.225Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}