Skip to content

all: enable makezero errchkjson noctx linters - #23174

Open
Sahil-4555 wants to merge 3 commits into
erigontech:mainfrom
Sahil-4555:linter/enable-makezero-errchkjson-noctx
Open

all: enable makezero errchkjson noctx linters#23174
Sahil-4555 wants to merge 3 commits into
erigontech:mainfrom
Sahil-4555:linter/enable-makezero-errchkjson-noctx

Conversation

@Sahil-4555

Copy link
Copy Markdown
Collaborator

Enables 3 bug-catching linter rules in .golangci.yml (makezero, errchkjson, and noctx) and resolves all existing violations across the codebase to ensure continuous CI protection against subtle runtime bugs.

1. makezero

  • What it prevents: Prevents silent slice corruption where make([]T, n) is followed by append(), which unintentionally prepends n zero-value items at the beginning of a slice.
  • Benefits: Guarantees slice allocations in Erigon are safe and clean, ensuring new code additions cannot introduce zero-padded array bugs into memory or state processing logic.

2. errchkjson

  • What it prevents: Prevents unhandled JSON serialization failures from json.Marshal, json.MarshalIndent, or json.Encoder.Encode failing silently when structs contain unsupported types, custom marshalers, or map keys.
  • Benefits: Improves API reliability and logging accuracy by ensuring JSON encoding errors in RPC, REST endpoints, and tools are caught and logged rather than producing corrupt/empty payloads.

3. noctx

  • What it prevents: Prevents network request hangs and uncancelable HTTP/socket operations created with http.NewRequest instead of context-aware functions.
  • Benefits: Ensures HTTP requests respect parent context timeouts and cancellation signals, preventing leaking goroutines and stuck network calls under heavy load or shutdown.

@Sahil-4555
Sahil-4555 force-pushed the linter/enable-makezero-errchkjson-noctx branch 2 times, most recently from 0e41ec1 to 8f05b71 Compare August 11, 2026 11:14
Comment thread cl/beacon/beaconhttp/api_test.go Outdated
})

req := httptest.NewRequest("GET", "/test", http.NoBody)
req := httptest.NewRequest("GET", "/test", http.NoBody) //nolint:noctx

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be:

ctx := t.Context(),
httptest.NewRequestWithContext(ctx, 

Comment thread cl/beacon/handler/blobs.go Outdated
index, ok := versionedHashesToIndex[common.HexToHash(hash)]
if ok {
indicies = append(indicies, index)
indicies = append(indicies, index) //nolint:makezero

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why need disable here?

Comment thread cl/beacon/router.go Outdated

func ListenAndServe(beaconHandler *LayeredBeaconHandler, routerCfg beacon_router_configuration.RouterConfiguration) error {
listener, err := net.Listen(routerCfg.Protocol, routerCfg.Address)
listener, err := net.Listen(routerCfg.Protocol, routerCfg.Address) //nolint:noctx

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems not-passing rootCtx here is a bug

also i see: go ListenAndServe() - err ignored (or don't return it)

func downloadGenesisState(url string) ([]byte, error) {
// Download genesis state by wget the url. MUST NOT RETURN NIL thorugh GET request. use go stnadard library
resp, err := http.Get(url)
resp, err := http.Get(url) //nolint:noctx

@AskAlexSharov AskAlexSharov Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems not passing root ctx here is a bug (also maybe need add some timeout here (if no default)

Comment thread cl/sentinel/handshake/handshake.go Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe need accept external ctx param

@Sahil-4555
Sahil-4555 force-pushed the linter/enable-makezero-errchkjson-noctx branch from 8f05b71 to 690cc6b Compare August 12, 2026 04:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants