Commit a882dd2
fix: drain until sentinel to prevent deadlock on early generator close
When concurrent_files > 1 and max_buffered_batches is small, multiple
workers can be blocked on batch_queue.put() at the moment the consumer
closes early (e.g. due to a limit). The previous drain loop used
get_nowait() + empty() which had a race: empty() could return True
before a just-notified worker had a chance to put, leaving remaining
workers stuck on put() forever while executor.shutdown(wait=True) hung.
Fix: replace the racy drain loop with a blocking drain-until-sentinel
loop. Each get() naturally wakes one blocked worker via not_full.notify();
that worker checks cancel and returns, eventually allowing the last worker
to put the sentinel. Stopping only on the sentinel guarantees all workers
have finished before we exit.
Also move batch_queue.put(_QUEUE_SENTINEL) outside remaining_lock to
avoid holding a lock during a potentially blocking call.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent caa079e commit a882dd2
File tree
2 files changed
+62
-8
lines changed- pyiceberg/io
- tests/io
2 files changed
+62
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1727 | 1727 | | |
1728 | 1728 | | |
1729 | 1729 | | |
1730 | | - | |
1731 | | - | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
1732 | 1733 | | |
1733 | 1734 | | |
1734 | 1735 | | |
1735 | 1736 | | |
1736 | 1737 | | |
| 1738 | + | |
1737 | 1739 | | |
1738 | 1740 | | |
1739 | 1741 | | |
1740 | 1742 | | |
1741 | 1743 | | |
| 1744 | + | |
1742 | 1745 | | |
1743 | 1746 | | |
1744 | 1747 | | |
| |||
1747 | 1750 | | |
1748 | 1751 | | |
1749 | 1752 | | |
1750 | | - | |
1751 | | - | |
1752 | | - | |
1753 | | - | |
1754 | | - | |
1755 | | - | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
1756 | 1763 | | |
1757 | 1764 | | |
1758 | 1765 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
145 | 192 | | |
146 | 193 | | |
147 | 194 | | |
| |||
0 commit comments