mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(webconsole): optimized guacd error log (#18904)
This commit is contained in:
@@ -19,7 +19,14 @@ import (
|
||||
"io"
|
||||
"net"
|
||||
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/gotypes"
|
||||
)
|
||||
|
||||
const (
|
||||
TunnerClose = errors.Error("TunnerClose")
|
||||
InvalidInstruction = errors.Error("InvalidInstruction")
|
||||
)
|
||||
|
||||
type GuacamoleTunnel struct {
|
||||
@@ -42,6 +49,9 @@ func (self *GuacamoleTunnel) ReadOne() (*Instruction, error) {
|
||||
for {
|
||||
select {
|
||||
case instruct := <-self.instructs:
|
||||
if gotypes.IsNil(instruct) {
|
||||
return nil, InvalidInstruction
|
||||
}
|
||||
return instruct, nil
|
||||
default:
|
||||
}
|
||||
@@ -71,12 +81,12 @@ func (self *GuacamoleTunnel) start() error {
|
||||
default:
|
||||
n, err := self.conn.Read(buf)
|
||||
if err != nil && err != io.EOF {
|
||||
self.err <- err
|
||||
self.err <- errors.Wrapf(err, "Read")
|
||||
return
|
||||
}
|
||||
instructions, _left, err := parse(append(left, buf[:n]...))
|
||||
if err != nil {
|
||||
self.err <- err
|
||||
self.err <- errors.Wrapf(err, "parse instruct")
|
||||
return
|
||||
}
|
||||
left = _left
|
||||
@@ -90,7 +100,8 @@ func (self *GuacamoleTunnel) start() error {
|
||||
}
|
||||
|
||||
func (self *GuacamoleTunnel) Stop() {
|
||||
self.err <- fmt.Errorf("guacamole tunnel stoped")
|
||||
defer self.conn.Close()
|
||||
self.err <- TunnerClose
|
||||
self.stopChan <- true
|
||||
}
|
||||
|
||||
@@ -121,7 +132,7 @@ func (self *GuacamoleTunnel) Handshake() error {
|
||||
}
|
||||
|
||||
if args.Opcode != "args" {
|
||||
return errors.Errorf("Invalid instruct %s", args.String())
|
||||
return errors.Wrapf(InvalidInstruction, args.String())
|
||||
}
|
||||
|
||||
for i, arg := range args.Args {
|
||||
@@ -160,7 +171,7 @@ func (self *GuacamoleTunnel) Handshake() error {
|
||||
}
|
||||
|
||||
if ready.Opcode != "ready" {
|
||||
return fmt.Errorf("invalid ready instruction %s", ready.String())
|
||||
return errors.Wrapf(InvalidInstruction, ready.String())
|
||||
}
|
||||
|
||||
if len(ready.Args) == 0 {
|
||||
@@ -168,5 +179,6 @@ func (self *GuacamoleTunnel) Handshake() error {
|
||||
}
|
||||
|
||||
self.opts.ConnectionId = ready.Args[0]
|
||||
log.Debugf("connection id %s", self.opts.ConnectionId)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
@@ -23,7 +22,6 @@ import (
|
||||
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/gotypes"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/webconsole/guac"
|
||||
"yunion.io/x/onecloud/pkg/webconsole/options"
|
||||
@@ -104,18 +102,15 @@ func (s *RDPServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
for {
|
||||
ins, err := tunnel.ReadOne()
|
||||
if err != nil {
|
||||
log.Errorf("read one error: %v", err)
|
||||
return
|
||||
}
|
||||
if options.Options.RdpSessionTimeoutMinutes > 0 && timer != nil {
|
||||
timer.Reset(time.Duration(options.Options.RdpSessionTimeoutMinutes) * time.Minute)
|
||||
}
|
||||
if !gotypes.IsNil(ins) {
|
||||
err = ws.WriteMessage(websocket.TextMessage, []byte(ins.String()))
|
||||
if err != nil {
|
||||
log.Errorf("Failed writing to guacd %s: %v", ins.String(), err)
|
||||
return
|
||||
}
|
||||
err = ws.WriteMessage(websocket.TextMessage, []byte(ins.String()))
|
||||
if err != nil {
|
||||
log.Errorf("Failed writing to guacd %s: %v", ins.String(), err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
@@ -127,11 +122,11 @@ func (s *RDPServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
for {
|
||||
_, p, err := ws.ReadMessage()
|
||||
if err != nil {
|
||||
if errors.Cause(err) != io.EOF {
|
||||
log.Errorf("read message error %v", err)
|
||||
if websocket.IsCloseError(err, websocket.CloseNormalClosure) {
|
||||
return
|
||||
}
|
||||
continue
|
||||
log.Errorf("read message error %v", err)
|
||||
return
|
||||
}
|
||||
if options.Options.RdpSessionTimeoutMinutes > 0 && timer != nil {
|
||||
timer.Reset(time.Duration(options.Options.RdpSessionTimeoutMinutes) * time.Minute)
|
||||
@@ -169,7 +164,7 @@ func (s *RDPServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
defer setDone()
|
||||
|
||||
err = tunnel.Wait()
|
||||
if err != nil {
|
||||
if err != nil && errors.Cause(err) != guac.TunnerClose {
|
||||
log.Errorf("wait error: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user