Commit 579ce11
[chore][stanza/namedpipe] Refactor the namedpipe input to remove the fsnotify (#39529)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
The current logic is that the input starts 2 goroutines, one for
watching for write events, and another one listens from `watcher.C` and
kick off the process. In other words, it relies on a write event to
start to read from the pipe.
When an active writer is writing to the pipe, and the collector exits
for whatever reason (or simply can't consume fast enough), the pipe
buffer can be filled and no write can come in. When no write happens,
the watcher doesn't receive any write event, and won't kick off the
process to read the pipe. This is effectively a deadlock, the writer
can't write to the pipe because the pipe buffer is full, and the
collector won't read from the pipe because no write event triggered.
Refactor the namedpipe input to get rid of the watcher. The input will
now keep reading from pipe. If no data or no external writer, it blocks
at the `scan.Scan()` wait for new data or an error when pipe is closed.
#### How to reproduce the bug
A simple python script to write to a named pipe periodically:
```python
import os
import time
PIPE_PATH = "/tmp/my_named_pipe"
try:
fd = os.open(PIPE_PATH, os.O_RDWR | os.O_APPEND | os.O_NONBLOCK)
except OSError as e:
print(f"Failed to open pipe: {e}")
exit(1)
msg = b"x" * 1024 * 10 + b"\n" # 10 KB message with a newline at the end
while True:
try:
os.write(fd, msg)
print("write ok")
except BlockingIOError:
print("PIPE FULL - write blocked")
time.sleep(1)
```
The minimal Otel collector config:
```yaml
receivers:
namedpipe:
path: /tmp/my_named_pipe
mode: 0600
exporters:
debug:
verbosity: basic
service:
pipelines:
logs:
receivers: [namedpipe]
processors: []
exporters: [debug]
```
1. Start the python script to write the pipe to full (when seeing "PIPE
FULL - write blocked"). It's usually the 7th write if the pipe buffer is
64K (default value).
2. Start the otel collector and see it doesn't process anything from the
pipe.
<!--Describe what testing was performed and which tests were added.-->
#### Testing
Passed all current unit tests. Also tested locally with the steps above
to confirm it reads from the pipe from the start.
---------
Signed-off-by: Mengnan Gong <namco1992@gmail.com>
Co-authored-by: Daniel Jaglowski <jaglows3@gmail.com>1 parent edc64d2 commit 579ce11
File tree
6 files changed
+94
-105
lines changed- pkg/stanza
- operator/input/namedpipe
- receiver/namedpipereceiver
6 files changed
+94
-105
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | 9 | | |
11 | 10 | | |
12 | 11 | | |
| |||
45 | 44 | | |
46 | 45 | | |
47 | 46 | | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| 24 | + | |
| 25 | + | |
23 | 26 | | |
24 | 27 | | |
25 | 28 | | |
| |||
55 | 58 | | |
56 | 59 | | |
57 | 60 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
67 | | - | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
| 73 | + | |
| 74 | + | |
94 | 75 | | |
95 | 76 | | |
96 | 77 | | |
97 | 78 | | |
98 | 79 | | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | 80 | | |
104 | 81 | | |
105 | 82 | | |
106 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
107 | 88 | | |
108 | 89 | | |
109 | 90 | | |
110 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
111 | 116 | | |
112 | 117 | | |
113 | 118 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
150 | 150 | | |
151 | 151 | | |
152 | 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 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
35 | 34 | | |
36 | 35 | | |
37 | 36 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments