- Notifications
You must be signed in to change notification settings - Fork914
Commit87dc247
feat: fail CI when
Publishing inside a db transaction can lead to database connectionstarvation/contention since it requires its own connection.This ruleguard rule (one-shotted by Claude Sonnet 3.7 and finalized by@Emyrk) will detect two of the following 3 instances:```gotype Nested struct {ps pubsub.Pubsub}func TestFail(t *testing.T) {t.Parallel()db, ps := dbtestutil.NewDB(t)nested := &Nested{ps: ps,}// will catch this_ = db.InTx(func(_ database.Store) error {_, _ = fmt.Printf("")_ = ps.Publish("", []byte{})return nil}, nil)// will catch this_ = db.InTx(func(_ database.Store) error {_ = nested.ps.Publish("", []byte{})return nil}, nil)// will NOT catch this_ = db.InTx(func(_ database.Store) error {blah(ps)return nil}, nil)}func blah(ps pubsub.Pubsub) {ps.Publish("", []byte{})}```The ruleguard doesn't recursively introspect function calls so only thefirst two cases will be guarded against, but it's better than nothing.<img width="1444" alt="image"src="https://github.com/user-attachments/assets/8ffa0d88-16a0-41a9-9521-21211910dec9"/>---------Signed-off-by: Danny Kopping <dannykopping@gmail.com>Co-authored-by: Steven Masley <stevenmasley@gmail.com>pubsub.Publish
calls are found in db transactions (#17903)1 parent4412f19 commit87dc247
1 file changed
+36
-0
lines changedLines changed: 36 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
134 | 134 |
| |
135 | 135 |
| |
136 | 136 |
| |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 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 | + | |
137 | 173 |
| |
138 | 174 |
| |
139 | 175 |
| |
|
0 commit comments
Comments
(0)