Skip to content

Stub at fixing leak #405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions datamodel/low/v2/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ func (s *SecurityDefinitions) Build(ctx context.Context, _, root *yaml.Node, idx
var defLabel *yaml.Node
totalDefinitions := 0

// TODO:
// Same issue here
buildFunc := func(label *yaml.Node, value *yaml.Node, idx *index.SpecIndex,
r chan definitionResult[*SecurityScheme], e chan error,
) {
Expand Down
12 changes: 12 additions & 0 deletions datamodel/low/v2/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package v2

import (
"testing"

"go.uber.org/goleak"
)

func TestMain(m *testing.M) {
// This will report any leaked goroutines throughout the test suite
goleak.VerifyTestMain(m)
}
38 changes: 26 additions & 12 deletions datamodel/low/v2/path_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,25 +147,37 @@ func (p *PathItem) Build(ctx context.Context, _, root *yaml.Node, idx *index.Spe
}
}

if len(ops) <= 0 {
return nil // nothing to do.
}

// derive a cancellable ctx
buildOpCtx, cancel := context.WithCancel(ctx)
defer cancel()

// all operations have been superficially built,
// now we need to build out the operation, we will do this asynchronously for speed.
opBuildChan := make(chan struct{})
opErrorChan := make(chan error)
opBuildChan := make(chan struct{}, len(ops))
opErrorChan := make(chan error, len(ops))

var buildOpFunc = func(op low.NodeReference[*Operation]) {
defer func() { opBuildChan <- struct{}{} }()

var buildOpFunc = func(op low.NodeReference[*Operation], ch chan<- struct{}, errCh chan<- error) {
er := op.Value.Build(ctx, op.KeyNode, op.ValueNode, idx)
if er != nil {
errCh <- er
// If we’ve already been canceled, skip running Build at all
select {
case <-buildOpCtx.Done():
return
default:
}
ch <- struct{}{}
}

if len(ops) <= 0 {
return nil // nothing to do.
if err := op.Value.Build(ctx, op.KeyNode, op.ValueNode, idx); err != nil {
opErrorChan <- err
cancel()
}
}

for _, op := range ops {
go buildOpFunc(op, opBuildChan, opErrorChan)
go buildOpFunc(op)
}

n := 0
Expand All @@ -179,7 +191,9 @@ func (p *PathItem) Build(ctx context.Context, _, root *yaml.Node, idx *index.Spe
}
}

// make sure we don't exit before the path is finished building.
// TODO:
// I am not sure about this one.
// Should it not be before we call buildOpFunc??
if len(ops) > 0 {
wg.Wait()
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/speakeasy-api/jsonpath v0.6.1
github.com/stretchr/testify v1.10.0
github.com/wk8/go-ordered-map/v2 v2.1.9-0.20240815153524-6ea36470d1bd
go.uber.org/goleak v1.3.0
gopkg.in/yaml.v3 v3.0.1
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/wk8/go-ordered-map/v2 v2.1.9-0.20240815153524-6ea36470d1bd h1:dLuIF2kX9c+KknGJUdJi1Il1SDiTSK158/BB9kdgAew=
github.com/wk8/go-ordered-map/v2 v2.1.9-0.20240815153524-6ea36470d1bd/go.mod h1:DbzwytT4g/odXquuOCqroKvtxxldI4nb3nuesHF/Exo=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
Loading