Sobes.tech
Middle+

Tell me about failures from your work experience

sobes.tech AI

Answer from AI

One of the major fails happened when I mishandled an error in a goroutine, and it silently exited without logging. As a result, some data was not processed, and we couldn't understand the reason for a long time.

Another case was a data race during parallel access to a map without synchronization. This caused unpredictable bugs and crashes.

From these mistakes, I learned important lessons:

  • Always handle errors in goroutines and log them
  • Use channels or sync.Mutex to protect shared resources
  • Write concurrency tests to detect races

For example, for safe access to a map:

Type SafeMap struct {
    mu sync.Mutex
    m  map[string]int
}

func (s *SafeMap) Get(key string) (int, bool) {
    s.mu.Lock()
    defer s.mu.Unlock()
    val, ok := s.m[key]
    return val, ok
}

func (s *SafeMap) Set(key string, val int) {
    s.mu.Lock()
    defer s.mu.Unlock()
    s.m[key] = val
}

Such practices help avoid common mistakes in Go.

Tell me about failures from your work experience… - sobes.tech