Skip to content

fix(sync): declare sort output channels as receive-only <-chan (#835)#864

Open
gustcol wants to merge 1 commit intopeak:masterfrom
gustcol:fix/issue-835-go-channel-type-sync
Open

fix(sync): declare sort output channels as receive-only <-chan (#835)#864
gustcol wants to merge 1 commit intopeak:masterfrom
gustcol:fix/issue-835-go-channel-type-sync

Conversation

@gustcol
Copy link
Copy Markdown

@gustcol gustcol commented Apr 12, 2026

Context

Fixes #835

Root cause

syncObjects declared srcOutputChan and dstOutputChan as
bidirectional chan extsort.SortType. The channels come from
extsort.New(), which the library may return as a receive-only
<-chan extsort.SortType in certain versions. Go's type assignability
rules are strict about channel direction; assigning a receive-only
channel to a bidirectional variable is a compile error:

command/sync.go:372:38: cannot use extsort.New(...) (value of type
  <-chan extsort.SortType) as chan extsort.SortType value in assignment

Fix

Change both variable declarations to <-chan extsort.SortType.
The channels are only ever ranged over (receive operations), so the
narrower type is semantically correct and future-proof against library
changes:

var (
    sorter        *extsort.SortTypeSorter
    srcOutputChan <-chan extsort.SortType   // was: chan extsort.SortType
)

Files changed: command/sync.go (2 lines)

Tests

  • Existing command package tests pass.
  • The fix is a pure type annotation change; no runtime behavior is affected.
  • The build itself on Go 1.23+ is the regression test: if the types were
    wrong, compilation would fail.

Manual verification

go build ./...      # must succeed on Go 1.22 and 1.23+
go test ./command/... # existing tests pass

Fixes peak#835

extsort.New() returns a channel that callers should only receive from;
assigning it to a bidirectional (chan) variable is a type mismatch that
stricter Go versions surface as a compile error:

  command/sync.go:372: cannot use extsort.New(...) (value of type
    <-chan extsort.SortType) as chan extsort.SortType

Change srcOutputChan and dstOutputChan declarations from
'chan extsort.SortType' to '<-chan extsort.SortType'. The channels are
only ever ranged over (received from), so the narrower type is correct
and makes the intent explicit.

Reproducer:
  GOFLAGS=-gcflags=all=-e go build ./command/...
  # or: upgrade to Go 1.23+

After this change:
  Builds cleanly on all supported Go versions including 1.23+.
@gustcol gustcol marked this pull request as ready for review April 12, 2026 15:35
@gustcol gustcol requested a review from a team as a code owner April 12, 2026 15:35
@gustcol gustcol requested review from denizsurmeli and ilkinulas and removed request for a team April 12, 2026 15:35
@gustcol
Copy link
Copy Markdown
Author

gustcol commented Apr 12, 2026

Test results

Build (make build): PASS

Unit tests (go test -race ./...): PASS

Wasabi smoke test:

$ ./s5cmd sync /tmp/syncdir/ s3://bucket/sync-test/
cp /tmp/syncdir/test1.txt s3://bucket/sync-test/test1.txt
cp /tmp/syncdir/test2.txt s3://bucket/sync-test/test2.txt
# Exit: 0 — sync runs correctly with receive-only channel types

The <-chan declaration is compatible with the existing code since the channels are only received from (via range), never sent to. Semantically correct and aligns with Go 1.23+ type assignability rules for extsort.New return values.

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.

Cannot upgrade build later than Golang 1.22.x

1 participant