You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When decomposedfs is interacting with network filesystems like NFS, CephFS, GlusterFS ... it may run into timeouts or network disconnects. To be able to gracefully handle these timeouts we need to implement a timeout. I propose to use a dedicated package that Extends the signature of os.Stat() and other calls to include a context an timeout parameter. One example would be:
package os
import (
"context""os""time""go.opentelemetry.io/otel""go.opentelemetry.io/otel/attribute""go.opentelemetry.io/otel/codes""go.opentelemetry.io/otel/trace"
)
vartracer trace.Tracerfuncinit() {
tracer=otel.Tracer("github.com/cs3org/reva/pkg/os")
}
// Stat returns a FileInfo describing the named file.// If there is an error, it will be of type *PathError.funcStat(ctx context.Context, timeout time.Duration, namestring) (os.FileInfo, error) {
_, span:=tracer.Start(ctx, "os.Stat")
deferspan.End()
span.SetAttributes(attribute.String("path", name))
// Channel used to receive the result from os.Stat functionch:=make(chan os.FileInfo, 1)
errCh:=make(chanerror, 1)
varcancel context.CancelFunciftimeout>0 {
ctx, cancel=context.WithTimeout(ctx, timeout)
defercancel()
}
// Start the doSomething functiongofunc(namestring) {
fi, err:=os.Stat(name)
iferr==nil {
ch<-fi
} else {
errCh<-err
}
close(ch)
close(errCh)
}(name)
select {
case<-ctx.Done():
span.SetStatus(codes.Error, ctx.Err().Error())
returnnil, ctx.Err()
caseerr:=<-errCh:
span.SetStatus(codes.Error, err.Error())
returnnil, errcaseresult:=<-ch:
span.SetStatus(codes.Ok, "")
returnresult, nil
}
}
[...otherfunctionslike os.Readfile, os.Open, os.Mkdir...]
It adds tracing and a timeout mechanism. I kept an explicit timeout parameter because the wrapper handles the timeout itself.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 10 days if no further activity occurs. Thank you for your contributions.
When decomposedfs is interacting with network filesystems like NFS, CephFS, GlusterFS ... it may run into timeouts or network disconnects. To be able to gracefully handle these timeouts we need to implement a timeout. I propose to use a dedicated package that Extends the signature of
os.Stat()
and other calls to include a context an timeout parameter. One example would be:It adds tracing and a timeout mechanism. I kept an explicit timeout parameter because the wrapper handles the timeout itself.
Related: golang/go#20280
The text was updated successfully, but these errors were encountered: