20230121日志
2023年1月21日
202301,
goroutine停止,
for循环下goroutine闭包,
select多个channel,
noticication channel,
nil channel,
buffered or not buffered channel,
waitGroup,
append是否会导致Data race
golang # 传播不合适的context # func handler(w http.ResponseWriter, r *http.Request) { response, err := doSomeTask(r.Context(), r) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } go func() { err := publish(r.Context(), response) // Do something with err }() writeResponse(response) } type detach struct { ctx context.Context } func (d detach) Deadline() (time.Time, bool) { return time.Time{}, false } func (d detach) Done() <-chan struct{} { return nil } func (d detach) Err() error { return nil } func (d detach) Value(key any) any { return d. ...