mirror of
				https://gitea.com/Lydanne/buildx.git
				synced 2025-11-04 18:13:42 +08:00 
			
		
		
		
	Merge pull request #2657 from jsternberg/metricwriter-race-condition
metrics: add mutex to the metric writer
This commit is contained in:
		@@ -45,6 +45,7 @@ var re = sync.OnceValue(func() *rePatterns {
 | 
				
			|||||||
type metricWriter struct {
 | 
					type metricWriter struct {
 | 
				
			||||||
	recorders []metricRecorder
 | 
						recorders []metricRecorder
 | 
				
			||||||
	attrs     attribute.Set
 | 
						attrs     attribute.Set
 | 
				
			||||||
 | 
						mu        sync.Mutex
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func newMetrics(mp metric.MeterProvider, attrs attribute.Set) *metricWriter {
 | 
					func newMetrics(mp metric.MeterProvider, attrs attribute.Set) *metricWriter {
 | 
				
			||||||
@@ -63,6 +64,9 @@ func newMetrics(mp metric.MeterProvider, attrs attribute.Set) *metricWriter {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (mw *metricWriter) Write(ss *client.SolveStatus) {
 | 
					func (mw *metricWriter) Write(ss *client.SolveStatus) {
 | 
				
			||||||
 | 
						mw.mu.Lock()
 | 
				
			||||||
 | 
						defer mw.mu.Unlock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, recorder := range mw.recorders {
 | 
						for _, recorder := range mw.recorders {
 | 
				
			||||||
		recorder.Record(ss)
 | 
							recorder.Record(ss)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user