Grokking Concurrency in Go
Vote

0% completed

​

The Concurrent Map

A team added visit counting to a web service. Each request handler ran in its own goroutine and increased a counter in a shared map[string]int. The change passed its tests, which sent one request at a time. Under real traffic, the service stopped within minutes. The program below reproduces the failure, and it ends with the same error the log showed:

Output (trimmed):

fatal error: concurrent map writes goroutine 8 [running]: internal/runtime/maps.fatal(...) main.main.func1()

The map was never safe for concurrent writes

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content