Skip to content

Commit

Permalink
Some changes that fix interface leaks
Browse files Browse the repository at this point in the history
Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com>
  • Loading branch information
NikitaSkrynnik committed Jun 26, 2024
1 parent a763a15 commit 44902a1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 26 deletions.
18 changes: 10 additions & 8 deletions pkg/networkservice/common/monitor/eventloop.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,17 @@ func (cev *eventLoop) eventLoop() {
}
if err != nil {
// If we get an error, we've lost our connection... Send Down update
connOut := cev.conn.Clone()
connOut.State = networkservice.State_DOWN
eventOut := &networkservice.ConnectionEvent{
Type: networkservice.ConnectionEventType_UPDATE,
Connections: map[string]*networkservice.Connection{
cev.conn.GetId(): connOut,
},
connOut := cev.conn.Clon e()

Check failure on line 81 in pkg/networkservice/common/monitor/eventloop.go

View workflow job for this annotation

GitHub Actions / code-cov (ubuntu-latest)

syntax error: unexpected e at end of statement

Check failure on line 81 in pkg/networkservice/common/monitor/eventloop.go

View workflow job for this annotation

GitHub Actions / code-cov (macos-latest)

syntax error: unexpected e at end of statement

Check failure on line 81 in pkg/networkservice/common/monitor/eventloop.go

View workflow job for this annotation

GitHub Actions / build-and-test / build-and-test (ubuntu-latest)

syntax error: unexpected e at end of statement

Check failure on line 81 in pkg/networkservice/common/monitor/eventloop.go

View workflow job for this annotation

GitHub Actions / build-and-test / build-and-test (macos-latest)

syntax error: unexpected e at end of statement

Check failure on line 81 in pkg/networkservice/common/monitor/eventloop.go

View workflow job for this annotation

GitHub Actions / golangci-lint / golangci-lint

syntax error: unexpected e at end of statement (typecheck)

Check failure on line 81 in pkg/networkservice/common/monitor/eventloop.go

View workflow job for this annotation

GitHub Actions / golangci-lint / golangci-lint

expected ';', found e (typecheck)

Check failure on line 81 in pkg/networkservice/common/monitor/eventloop.go

View workflow job for this annotation

GitHub Actions / golangci-lint / golangci-lint

syntax error: unexpected e at end of statement) (typecheck)
if connOut != nil {
connOut.State = networkservice.State_DOWN
eventOut := &networkservice.ConnectionEvent{
Type: networkservice.ConnectionEventType_UPDATE,
Connections: map[string]*networkservice.Connection{
cev.conn.GetId(): connOut,
},
}
_ = cev.eventConsumer.Send(eventOut)
}
_ = cev.eventConsumer.Send(eventOut)
return
}
_ = cev.eventConsumer.Send(eventIn)
Expand Down
30 changes: 15 additions & 15 deletions pkg/networkservice/common/monitor/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ import (
"context"

"github.com/golang/protobuf/ptypes/empty"
"github.com/pkg/errors"

"github.com/networkservicemesh/sdk/pkg/networkservice/common/clientconn"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata"
"github.com/networkservicemesh/sdk/pkg/tools/postpone"

"github.com/networkservicemesh/api/pkg/api/networkservice"

Expand Down Expand Up @@ -58,7 +55,7 @@ func NewServer(chainCtx context.Context, monitorServerPtr *networkservice.Monito
}

func (m *monitorServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) {
closeCtxFunc := postpone.ContextWithValues(ctx)
// closeCtxFunc := postpone.ContextWithValues(ctx)
// Cancel any existing eventLoop
cancelEventLoop, loaded := loadAndDelete(ctx, metadata.IsClient(m))
if loaded {
Expand Down Expand Up @@ -86,17 +83,20 @@ func (m *monitorServer) Request(ctx context.Context, request *networkservice.Net

// If we have a clientconn ... we must be part of a passthrough server, and have a client to pass
// events through from, so start an eventLoop
cc, ccLoaded := clientconn.Load(ctx)
if ccLoaded {
cancelEventLoop, eventLoopErr := newEventLoop(m.chainCtx, m.MonitorConnectionServer.(EventConsumer), cc, conn)
if eventLoopErr != nil {
closeCtx, closeCancel := closeCtxFunc()
defer closeCancel()
_, _ = next.Client(closeCtx).Close(closeCtx, conn)
return nil, errors.Wrap(eventLoopErr, "unable to monitor")
}
store(ctx, metadata.IsClient(m), cancelEventLoop)
}
// cc, ccLoaded := clientconn.Load(ctx)
// log.FromContext(ctx).Infof("ccLoaded")
// if ccLoaded {
// log.FromContext(ctx).Infof("newEventLoop")
// cancelEventLoop, eventLoopErr := newEventLoop(m.chainCtx, m.MonitorConnectionServer.(EventConsumer), cc, conn)
// if eventLoopErr != nil {
// closeCtx, closeCancel := closeCtxFunc()
// defer closeCancel()
// _, _ = next.Client(closeCtx).Close(closeCtx, conn)
// return nil, errors.Wrap(eventLoopErr, "unable to monitor")
// }
// log.FromContext(ctx).Infof("STORE")
// store(ctx, metadata.IsClient(m), cancelEventLoop)
// }

return conn, nil
}
Expand Down
18 changes: 17 additions & 1 deletion pkg/networkservice/common/timeout/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/networkservicemesh/sdk/pkg/networkservice/common/begin"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata"
"github.com/networkservicemesh/sdk/pkg/tools/clock"
"github.com/networkservicemesh/sdk/pkg/tools/log"

"github.com/networkservicemesh/api/pkg/api/networkservice"

Expand Down Expand Up @@ -59,9 +60,12 @@ func (s *timeoutServer) Request(ctx context.Context, request *networkservice.Net
}

conn, err = next.Server(ctx).Request(ctx, request)
logger := log.FromContext(ctx).WithField("TIMEOUT", "")
logger.Infof("BACKWARD")
if err != nil {
return nil, err
}
logger.Infof("NO ERROR, CALCULATING TIMEOUT")

expirationTimestamp := conn.GetPrevPathSegment().GetExpires()
if expirationTimestamp == nil {
Expand All @@ -72,14 +76,26 @@ func (s *timeoutServer) Request(ctx context.Context, request *networkservice.Net
if oldCancel, loaded := loadAndDelete(ctx, metadata.IsClient(s)); loaded {
oldCancel()
}

logger.Infof("EXPIRATION TIME: %v", expirationTime.String())

logger.Infof("STORE CANCEL TIMEOUT")

store(ctx, metadata.IsClient(s), cancel)
eventFactory := begin.FromContext(ctx)
afterCh := timeClock.After(timeClock.Until(expirationTime) - requestTimeout)
after := timeClock.Until(expirationTime) - requestTimeout

// after /= 3

logger.Infof("TIMEOUT SHOULD OCCUR AFTER: %v", after.String())
afterCh := timeClock.After(after)

go func(cancelCtx context.Context, afterCh <-chan time.Time) {
select {
case <-cancelCtx.Done():
logger.Infof("<-cancelCtx.Done()")
case <-afterCh:
logger.Infof("<-afterCh")
eventFactory.Close(begin.CancelContext(cancelCtx))
}
}(cancelCtx, afterCh)
Expand Down
11 changes: 9 additions & 2 deletions pkg/networkservice/common/updatepath/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,15 @@ func (i *updatePathClient) Request(ctx context.Context, request *networkservice.
return nil, err
}

conn.Id = conn.Path.PathSegments[index].Id
conn.Path.Index = index
segments := conn.GetPath().GetPathSegments()
if segments != nil && len(segments) > int(index) {
conn.Id = segments[index].Id
}

path := conn.GetPath()
if path != nil {
path.Index = index
}

return conn, nil
}
Expand Down

0 comments on commit 44902a1

Please sign in to comment.