-
Notifications
You must be signed in to change notification settings - Fork 178
fix: lazy load version, build correct multipart #305
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should hoist:
err = s.loadRemoteVersion()
if err != nil {
return err
}
fileReader := files.NewMultiFileReader(slf, true, s.version.LT(encodedAbsolutePathVersion))
In a private method of the shell that returns a file Reader and an error.
Except than this LGTM
6328245
to
8860c35
Compare
func (s *Shell) loadRemoteVersion() error { | ||
if s.version == nil { | ||
version, _, err := s.Version() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
remoteVersion, err := semver.New(version) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
s.versionOnce.Do(func() { | ||
s.version = remoteVersion | ||
}) | ||
} | ||
|
||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure the .Do
should englobe all of loadRemoteVersion's body.
Because this code will concurrently request the version number but save it only once, this leads to a data race between your s.version == nil
and s.version = remoteVersion
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll fix in separate PR.
See ipfs/kubo#10068.
Will be released in subsequent PR.