Rust & Go
Ownership, concurrency, errors and compiled service behavior.
50 troubleshooting guides · Page 2 / 3
Why does collecting Iterator<Item=Result<T,E>> stop at the first error?
Collecting into Result<Vec<T>,E> expresses all-or-error accumulation and short-circuits when an error occurs. It does not promise a report containing every invalid item.
Why is an error interface non-nil when its stored pointer is nil?
An interface carries a dynamic type and value. A typed nil pointer stored in error still supplies that type, so the interface need not equal nil.
Why does *T implement my Go interface while T does not?
Interface satisfaction depends on method sets. Pointer-receiver methods can make the pointer type satisfy an interface without giving the value type the same set.
Does the classic loop-variable capture bug still apply under Go 1.22 semantics?
It depends on language-version semantics and how the variable is declared. Go 1.22 changed eligible loop-declared variables to per-iteration variables; an outer variable reused by assignment is different.
Why does editing a struct range variable leave my Go slice unchanged?
A range value can be a copy of the element. Editing that local struct does not necessarily replace the stored element.
Why does appending to a subslice change another slice’s data?
Slices may share a backing array. Append that fits capacity can write into storage visible through another slice.
Why does a tiny retained subslice keep a large buffer in memory?
A subslice still references its backing array. Small visible length does not imply a small retained allocation.
Why can a nil map be read but not assigned to?
A nil map supports certain reads but has no initialized insertion storage. A zero-value declaration is not the same as make when writes are required.
Why does map iteration change the order of my Go export?
Map traversal does not promise stable presentation order. One observed iteration sequence is not a reproducible file-format contract.
Why is a shared Go map unsafe even with only occasional writes?
An infrequent write can still overlap a read. Ordinary maps do not make that overlap safe because most traffic happens to be read-only.
How do I preserve a large JSON integer in a generic Go object?
Generic decoding into float64 can lose integer precision before the application inspects the value. Casting a rounded float back cannot restore original digits.
Why does encoding/json omit a struct field despite a JSON tag?
A JSON tag does not automatically expose an unexported field. A lowercase Go field can remain absent even when its intended wire name looks correct.
How can a Go JSON API distinguish zero from an omitted numeric field?
A plain numeric zero and absence can collapse under the selected omission policy. That is a schema problem when zero is an explicit meaningful update.
Why call cancel when a context timeout will eventually expire anyway?
Cancel releases resources associated with the derived context sooner than its deadline. Omitting it can retain timers or child relationships unnecessarily.
Why does abandoning a Go HTTP response body harm resource reuse?
The response body is a caller-managed resource. Failing to close it retains transport resources, while reuse can also depend on how its content was consumed.
Why does a Go HTTP call keep waiting when I created a timeout context nearby?
A context only affects work actually linked to it. Creating one beside a request does not attach its deadline automatically.
Who should close a result channel with several producers?
Closing promises there will be no more sends. A receiver or one producer closing while others still send can cause a panic.
Why does assigning nil to a channel disable its select case?
Send and receive on a nil channel cannot complete. Within select, that case stops participating; a closed channel behaves differently and can receive immediately.
Why does a producer leak after its consumer returns early?
A producer can remain blocked on a send after the only receiver stops. More buffered capacity only postpones the blocked point for sufficiently large work.
Why does defer Close inside a large loop exhaust file handles?
Deferred calls execute when the surrounding function returns, not at the end of each iteration. A long loop can therefore retain every opened file.
Why does a parent recover not catch a new goroutine’s panic?
Recovery applies within the panicking goroutine’s deferred path. A parent function’s defer is not a global exception boundary for separately executing workers.
Why can Wait return early when Add happens inside a new goroutine?
The waiter can observe zero before the scheduled worker increments the counter. Scheduling does not establish registration order.
Why does a value receiver defeat the mutex in my Go struct?
Copying the struct can duplicate the mutex while reference-valued fields still point to shared data. Calls then lock different mutexes around one resource.
Why does matching error text break after adding useful context?
Formatted text is not a stable error classification contract. Wrapping can preserve a cause while changing the message.
Ask your own question · Sign in to post questions and answers.