Procházet zdrojové kódy

Fix CI: benchmark lint exclusions and data race in doppel test

Benchmarks added in the per-connection-overhead work triggered errcheck
warnings (37 unchecked Close/Fprintf in tool/bench code) and a data race
on package-level `sink` variable written by concurrent goroutines.

- Exclude benchmarks/ and *_bench_test.go from errcheck/ineffassign
- Replace concurrent `sink = buf[X]` with runtime.KeepAlive(&buf)
pull/434/head
Alexey Dolotov před 1 měsícem
rodič
revize
930c99234b
2 změnil soubory, kde provedl 14 přidání a 5 odebrání
  1. 9
    0
      .golangci.toml
  2. 5
    5
      benchmarks/doppel_buf_test.go

+ 9
- 0
.golangci.toml Zobrazit soubor

19
 #     "thelper",
19
 #     "thelper",
20
 #     "varnamelen",
20
 #     "varnamelen",
21
 # ]
21
 # ]
22
+
23
+# Benchmark and tool code: unchecked Close/Write/Fprintf is fine.
24
+[[issues.exclude-rules]]
25
+path = 'benchmarks/'
26
+linters = ['errcheck', 'ineffassign']
27
+
28
+[[issues.exclude-rules]]
29
+path = '_bench_test\.go$'
30
+linters = ['errcheck', 'ineffassign']

+ 5
- 5
benchmarks/doppel_buf_test.go Zobrazit soubor

30
 		//   n, _ := c.p.writeStream.Read(buf[tls.SizeHeader : tls.SizeHeader+size])
30
 		//   n, _ := c.p.writeStream.Read(buf[tls.SizeHeader : tls.SizeHeader+size])
31
 		//   tls.WriteRecordInPlace(c.Conn, buf[:], n)
31
 		//   tls.WriteRecordInPlace(c.Conn, buf[:], n)
32
 		copy(buf[sizeHeader:], payload)
32
 		copy(buf[sizeHeader:], payload)
33
-		sink = buf[sizeHeader]
34
 		<-done
33
 		<-done
34
+		runtime.KeepAlive(&buf)
35
 	}()
35
 	}()
36
 
36
 
37
 	// goroutine 2: clock tick loop
37
 	// goroutine 2: clock tick loop
66
 		bp := bufPool.Get().(*[]byte)
66
 		bp := bufPool.Get().(*[]byte)
67
 		buf := *bp
67
 		buf := *bp
68
 		copy(buf[sizeHeader:], payload)
68
 		copy(buf[sizeHeader:], payload)
69
-		sink = buf[sizeHeader]
70
 		defer bufPool.Put(bp)
69
 		defer bufPool.Put(bp)
71
 		<-done
70
 		<-done
71
+		runtime.KeepAlive(&buf)
72
 	}()
72
 	}()
73
 
73
 
74
 	// goroutine 2: clock tick loop
74
 	// goroutine 2: clock tick loop
123
 				defer wg.Done()
123
 				defer wg.Done()
124
 				var buf [maxRecordSize]byte
124
 				var buf [maxRecordSize]byte
125
 				buf[0] = 1
125
 				buf[0] = 1
126
-				sink = buf[0]
127
 				<-done
126
 				<-done
127
+				runtime.KeepAlive(&buf)
128
 			}()
128
 			}()
129
 		}
129
 		}
130
 		time.Sleep(200 * time.Millisecond)
130
 		time.Sleep(200 * time.Millisecond)
154
 				defer wg.Done()
154
 				defer wg.Done()
155
 				var buf [maxRecordSize]byte
155
 				var buf [maxRecordSize]byte
156
 				copy(buf[sizeHeader:], payload)
156
 				copy(buf[sizeHeader:], payload)
157
-				sink = buf[sizeHeader]
158
 				<-done
157
 				<-done
158
+				runtime.KeepAlive(&buf)
159
 			}()
159
 			}()
160
 		}
160
 		}
161
 		time.Sleep(200 * time.Millisecond)
161
 		time.Sleep(200 * time.Millisecond)
186
 				bp := bufPool.Get().(*[]byte)
186
 				bp := bufPool.Get().(*[]byte)
187
 				buf := *bp
187
 				buf := *bp
188
 				copy(buf[sizeHeader:], payload)
188
 				copy(buf[sizeHeader:], payload)
189
-				sink = buf[sizeHeader]
190
 				defer bufPool.Put(bp)
189
 				defer bufPool.Put(bp)
191
 				<-done
190
 				<-done
191
+				runtime.KeepAlive(&buf)
192
 			}()
192
 			}()
193
 		}
193
 		}
194
 		time.Sleep(200 * time.Millisecond)
194
 		time.Sleep(200 * time.Millisecond)

Načítá se…
Zrušit
Uložit