Skip to content

Commit

Permalink
UX and performance changes
Browse files Browse the repository at this point in the history
* Do not log EOF errors, avoid polluting logs
* Trim space from tokens when reading from file
* Do not use dir based caching

The caching problem deserves a separate explanation.

Directory backend is not concurrent friendly - it has a
fundamental design flaw - multiple gorotuines writing to the
same file corrupt cache data.

This requires either redesign of the backend or switching
to boltdb backend for caching.

Boltdb backend uses transactions and is safe for concurrent
access. This PR changes local cache to use boltdb instead
of the dir backend that is now used only in tests.
  • Loading branch information
klizhentas committed Jan 22, 2018
1 parent e737ba4 commit f0da64f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,8 @@ const (
// at expected interval
RemoteClusterStatusOnline = "online"
)

const (
// SharedDirMode is a mode for a directory shared with group
SharedDirMode = 0750
)
3 changes: 2 additions & 1 deletion lib/auth/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ func readToken(token string) (string, error) {
if err != nil {
return "", nil
}
return string(out), nil
// trim newlines as tokens in files tend to have newlines
return strings.TrimSpace(string(out)), nil
}

// PackedKeys is a collection of private key, SSH host certificate
Expand Down
6 changes: 4 additions & 2 deletions lib/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,9 +639,11 @@ func (process *TeleportProcess) newLocalCache(clt auth.ClientI, cacheName []stri
if !process.Config.CachePolicy.Enabled {
return clt, nil
}

path := filepath.Join(append([]string{process.Config.DataDir, "cache"}, cacheName...)...)
cacheBackend, err := dir.New(backend.Params{"path": path})
if err := os.MkdirAll(path, teleport.SharedDirMode); err != nil {
return nil, trace.ConvertSystemError(err)
}
cacheBackend, err := boltbk.New(backend.Params{"path": path})
if err != nil {
return nil, trace.Wrap(err)
}
Expand Down
5 changes: 4 additions & 1 deletion lib/sshutils/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,10 @@ func (c *connectionWrapper) Read(b []byte) (int, error) {
buff := make([]byte, MaxVersionStringBytes)
n, err := c.Conn.Read(buff)
if err != nil {
log.Error(err)
// EOF happens quite often, don't pollute the logs with EOF
if err != io.EOF {
log.Error(err)
}
return n, err
}
// chop off extra unused bytes at the end of the buffer:
Expand Down

0 comments on commit f0da64f

Please sign in to comment.