Skip to content

Commit fb45851

Browse files
committed
feat: replace container ID with exec ID
1 parent 0447fd2 commit fb45851

File tree

12 files changed

+207
-80
lines changed

12 files changed

+207
-80
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ require (
3131
github.com/spf13/pflag v1.0.3 // indirect
3232
github.com/ugorji/go/codec v0.0.0-20190320090025-2dc34c0b8780 // indirect
3333
github.com/wrfly/ecp v0.1.1-0.20190725160759-97269b9e95f0
34-
github.com/wrfly/pubsub v0.0.0-20200307185349-b35c047681a4
34+
github.com/wrfly/pubsub v0.0.0-20200314104228-47828c5578b6
3535
github.com/yudai/gotty v2.0.0-alpha.3+incompatible
3636
golang.org/x/net v0.0.0-20190326090315-15845e8f865b
3737
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ github.com/ugorji/go/codec v0.0.0-20190320090025-2dc34c0b8780 h1:vG/gY/PxA3v3l04
7474
github.com/ugorji/go/codec v0.0.0-20190320090025-2dc34c0b8780/go.mod h1:iT03XoTwV7xq/+UGwKO3UbC1nNNlopQiY61beSdrtOA=
7575
github.com/wrfly/ecp v0.1.1-0.20190725160759-97269b9e95f0 h1:Zy3Chk4CvwAqJ6YgQym6hJQEk4JE7iPbHRfxkru6Zn0=
7676
github.com/wrfly/ecp v0.1.1-0.20190725160759-97269b9e95f0/go.mod h1:cmmFTD+MLlrDa3/EO3gjeKLKUhHiYP3cgaaJamIS1NU=
77-
github.com/wrfly/pubsub v0.0.0-20200307185349-b35c047681a4 h1:G8zs08Ln8gek2TpeM1dgYFlUepEK6JNCM966Sf1kT+8=
78-
github.com/wrfly/pubsub v0.0.0-20200307185349-b35c047681a4/go.mod h1:WFtPVb6GumrLEVcAHZPSbjZmvWgenDSi4ceFW7k1r30=
77+
github.com/wrfly/pubsub v0.0.0-20200314104228-47828c5578b6 h1:iuI+7TJcnnKB3WH08PmK5Y4c66Tf2XNXmnvLpIFFP30=
78+
github.com/wrfly/pubsub v0.0.0-20200314104228-47828c5578b6/go.mod h1:WFtPVb6GumrLEVcAHZPSbjZmvWgenDSi4ceFW7k1r30=
7979
github.com/yudai/gotty v2.0.0-alpha.3+incompatible h1:eUFSuV4B2g+Rj+PS3HxhvOGEu2klWRzsl/7z7T/NUJQ=
8080
github.com/yudai/gotty v2.0.0-alpha.3+incompatible/go.mod h1:QBg0hL6VTVdqQk0qoBYk631EHLRH+XtR4wtbVi64UJ4=
8181
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 h1:u+LnwYTOOW7Ukr/fppxEb1Nwz0AtPflrblfvUudpo+I=

resources/list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
{{ range $i, $e := .containers }}
3939
<tr {{ if (eq (mod $i 2) 1) -}}class="t c ver2"{{- end }}>
4040
<td class="column1" title="exec into container">
41-
<a href="/exec/{{ printf "%.12s" .ID }}" value="{{ .ID }}" target="_blank">{{ printf "%.12s" .ID }}</a>
41+
<a href="/e/{{ printf "%.12s" .ID }}" value="{{ .ID }}" target="_blank">{{ printf "%.12s" .ID }}</a>
4242
</td>
4343
{{- if $share -}}
4444
<td class="column2" title="{{ .Image }} | share tty">

route/asset/asset.go

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9613,48 +9613,48 @@ var _compress_bytes_12 = []byte("" +
96139613
"\x42\xb8\x50\x39\x5c\x70\xb8\x19\xc2\x78\xe8\x82\x69\x64\x00" +
96149614
"\x73\xe7\xe0\x86\x6c\x33\xbf\x5b\x0b\xf9\x6e\xfd\x42\x75\xf8" +
96159615
"\x53\x82\xcf\xc8\x80\x4b\xab\xa0\xd5\x40\xfa\xc6\x00\x09\x6d" +
9616-
"\x4e\xb4\x43\xc7\x9b\x0d\x14\x9a\x4b\x3b\x05\xf2\xbf\x68\x7c" +
9617-
"\x63\x08\x44\x0f\x9f\xa1\x2c\x09\xac\xa8\x58\x62\x4a\x5c\x97" +
9618-
"\xa9\x67\x2c\xd5\x33\xb4\x29\xf9\x63\x22\xa8\xfc\x41\xb2\x63" +
9619-
"\xb6\x49\x4c\x77\x24\xc7\x36\x3f\x56\xa8\x4d\xd7\x7b\x31\xc4" +
9620-
"\x9b\x36\xc4\x4a\x8e\x3b\x7b\x50\x96\xf0\x17\x78\x7b\x6b\xd7" +
9621-
"\xc7\xe3\x7c\x4d\xb6\x5c\xc5\x9a\x40\x4e\x2d\x1d\xb5\x9d\x6a" +
9622-
"\x64\xf1\xd9\xa6\x24\xae\x88\x8e\x67\xa3\x13\x6b\xeb\xfe\xcc" +
9623-
"\x30\x51\x98\x7f\x1d\xe1\x5e\x54\x07\x64\x9c\x23\x61\xef\xb8" +
9624-
"\x1c\x50\x70\xdb\x53\x50\x37\xad\xdd\xd8\xb7\xd3\xfb\x9e\xf6" +
9625-
"\x18\xdf\xf4\x18\x5d\x67\x3b\x14\xd2\xb6\x20\x85\x9a\x99\xa3" +
9626-
"\x5b\xf0\xd3\x54\x09\xa1\x9e\xd2\xf1\xff\x2d\xe5\x22\x1d\x5f" +
9627-
"\xef\xd5\x63\xe3\x6c\x86\x16\x1c\x55\x4f\x78\xed\xfd\x8c\x3d" +
9628-
"\xdb\x0b\xe3\x6d\x7f\x6b\xbe\x9a\x26\x29\x5c\xe6\xf8\xec\x67" +
9629-
"\xae\x0f\x66\xe4\x60\x3b\x3e\xb9\x11\xef\x7a\xfe\xbe\x28\xf6" +
9630-
"\x88\x7a\x85\x7a\x77\x2b\xba\x0b\xff\x61\xdb\xdf\xf7\xbc\xb9" +
9631-
"\x1e\x8e\x8d\xa7\xc8\x77\xf4\x23\xfc\xbb\x3d\xfd\xa4\xa7\x0f" +
9632-
"\x87\xaa\x99\x4f\x41\x69\xcf\xf3\x68\xa9\xb6\xfe\xf3\x5e\x88" +
9633-
"\xdd\xca\x06\x48\x26\x4b\x6b\x95\x6c\xe4\x1a\x07\xaf\x6e\x1d" +
9634-
"\x6d\x93\xd8\xaf\x39\xd5\xbe\x67\xee\x71\xab\xe2\x9f\x50\xab" +
9635-
"\xc2\x31\xab\xe2\x24\xf1\x37\x34\x3d\xd9\xa7\xa8\x35\xd6\xba" +
9636-
"\x6b\xc3\x7d\x07\x27\xcf\xf3\xc9\xdb\xaf\x05\x75\x30\x49\xdc" +
9637-
"\xbb\xbb\x0e\xdd\x88\xdd\xab\x71\xff\x69\xe7\xdf\xb5\x3b\x8f" +
9638-
"\xba\x16\xe8\x89\x56\x54\x43\xdb\x59\x21\x05\x89\x4f\xf0\xa9" +
9639-
"\x19\xff\xf2\x18\x06\x91\x6b\xc1\xc1\x15\x6c\x6a\x19\xae\xf9" +
9640-
"\xde\xc1\x74\x29\xab\xcb\x1e\x42\xab\xf9\x6c\x86\x7a\xd8\x02" +
9641-
"\x00\x34\xda\xa5\x96\x50\xaf\x44\x13\x6a\xf0\xf7\x6f\x0f\x91" +
9642-
"\xc6\x42\x50\x86\x61\x10\xbf\x0e\xae\x82\x60\x08\x97\x2d\x64" +
9643-
"\x86\xf6\xde\x5a\xcd\x27\x4b\x8b\x61\x70\xa0\xdd\x07\xc3\x8f" +
9644-
"\x35\xbd\xcf\x4f\x59\x8f\xb7\xcf\x57\x25\xc3\xc0\x2c\x19\x43" +
9645-
"\x63\x82\xab\x8e\x3e\xdc\x2a\x63\x4a\x1a\x25\x30\xe2\x72\xaa" +
9646-
"\xc2\xc0\xbf\x56\xee\x82\x2b\xc0\x88\x56\xdf\xad\x8f\x3e\xf0" +
9647-
"\x37\x17\x71\x05\x73\x4a\x8e\x81\x7c\x24\x35\xae\xce\xc9\xc7" +
9648-
"\x41\x8d\xc5\x88\x09\xa4\xfa\x11\x05\x56\x9e\xc2\x96\x85\x0a" +
9649-
"\xd4\x36\x24\xfe\x52\xac\x5e\xf3\x21\xb9\xf4\x9e\x2e\xc9\x10" +
9650-
"\x98\x2a\x38\xe6\xaf\x48\x8d\xf7\x61\x77\x5f\xe8\xbe\x42\xdc" +
9651-
"\x53\xdd\xfd\xe3\xf8\x3b\x00\x00\xff\xff\x94\xcd\xa8\x2f")
9616+
"\x4e\x34\xc6\x9b\x0d\x14\x9a\x4b\x3b\x05\xf2\xbf\x68\x7c\x63" +
9617+
"\x08\x44\x0f\x9f\xa1\x2c\x09\xac\xa8\x58\x62\x4a\x5c\x8b\xa9" +
9618+
"\x67\x2c\xd5\x33\xb4\x29\xf9\x63\x22\xa8\xfc\x41\xb2\x63\xb6" +
9619+
"\x49\x4c\x77\xf4\xc6\x36\x3f\x56\xa5\x4d\xcb\x7b\x31\xbe\x9b" +
9620+
"\x36\xbe\x4a\x8e\x3b\x78\x50\x96\xf0\x17\x78\x7b\x6b\xd7\xc7" +
9621+
"\x83\x7c\x4d\xb6\x5c\xc5\x9a\x40\x4e\x2d\x1d\xb5\x6d\x6a\x64" +
9622+
"\xf1\xd9\xa6\x24\xae\x88\x8e\x67\xa3\x13\x6b\xeb\xfe\xcc\x30" +
9623+
"\x51\x98\x7f\x1d\xe1\x5e\x54\x07\x64\x9c\x23\x61\xef\xac\x1c" +
9624+
"\x50\x70\xdb\x53\x50\x77\xac\xdd\xd8\xb7\xd3\xfb\x9e\xf6\x18" +
9625+
"\xdf\xf4\x18\x5d\x5b\x3b\x14\xd2\xb6\x1a\x85\x9a\x99\xa3\x5b" +
9626+
"\xf0\xd3\x54\x09\xa1\x9e\xd2\xf1\xff\x2d\xe5\x22\x1d\x5f\xef" +
9627+
"\xd5\x63\xe3\x6c\x86\x16\x1c\x55\x4f\x78\xed\xfd\x8c\x3d\xdb" +
9628+
"\x0b\xe3\x6d\x7f\x6b\xbe\x9a\x26\x29\x5c\xe6\xf8\xec\x67\xae" +
9629+
"\x0f\x66\xe4\x60\x2f\x3e\xb9\x11\xef\x7a\xfe\xbe\x28\xf6\x88" +
9630+
"\x7a\x85\x7a\x77\x2b\xba\x0b\xff\x61\xdb\xdf\xf7\xbc\xb9\x06" +
9631+
"\x8e\x8d\xa7\xc8\xb7\xf3\x23\xfc\xbb\x0d\xfd\xa4\xa7\x0f\x87" +
9632+
"\xaa\x99\x4f\x41\x69\xcf\xf3\x68\xa9\xb6\xfe\xf3\x5e\x88\xdd" +
9633+
"\xca\x06\x48\x26\x4b\x6b\x95\x6c\xe4\x1a\x07\xaf\xae\x1c\x6d" +
9634+
"\x93\xd8\xaf\x39\xd5\xbe\x61\xee\x71\xab\xe2\x9f\x50\xab\xc2" +
9635+
"\x31\xab\xe2\x24\xf1\x37\x34\x3d\xd9\xa7\xa8\x35\xd6\xba\x6b" +
9636+
"\xc3\x7d\x07\x27\xcf\xf3\xc9\xab\xaf\x05\x75\x30\x49\xdc\xbb" +
9637+
"\xb8\x0e\x5d\x87\xdd\x7b\x71\xff\x5d\xe7\x1f\xb5\x3b\x2f\xba" +
9638+
"\x16\xe8\x89\x56\x54\x43\xdb\x59\x21\x05\x89\x4f\xf0\xa9\x19" +
9639+
"\xff\xf2\x18\x06\x91\x6b\xc1\xc1\x15\x6c\x6a\x19\xae\xf9\xde" +
9640+
"\xc1\x74\x29\xab\x9b\x1e\x42\xab\xf9\x6c\x86\x7a\xd8\x02\x00" +
9641+
"\x34\xda\xa5\x96\x50\xaf\x44\x13\x6a\xf0\xf7\x6f\x0f\x91\xc6" +
9642+
"\x42\x50\x86\x61\x10\xbf\x0e\xae\x82\x60\x08\x97\x2d\x64\x86" +
9643+
"\xf6\xde\x5a\xcd\x27\x4b\x8b\x61\x70\xa0\xdd\x07\xc3\x8f\x35" +
9644+
"\xbd\xcf\x4f\x59\x8f\xb7\x6f\x57\x25\xc3\xc0\x2c\x19\x43\x63" +
9645+
"\x82\xab\x8e\x3e\xdc\x2a\x63\x4a\x1a\x25\x30\xe2\x72\xaa\xc2" +
9646+
"\xc0\x3f\x55\xee\x82\x2b\xc0\x88\x56\xdf\xad\x8f\x3e\xf0\x37" +
9647+
"\x17\x71\x05\x73\x4a\x8e\x81\x7c\x24\x35\xae\xce\xc9\xc7\x41" +
9648+
"\x8d\xc5\x88\x09\xa4\xfa\x11\x05\x56\x9e\xc2\x96\x85\x0a\xd4" +
9649+
"\x36\x24\xfe\x52\xac\x9e\xf2\x21\xb9\xf4\x9e\x2e\xc9\x10\x98" +
9650+
"\x2a\x38\xe6\xaf\x48\x8d\xf7\x61\x77\x9f\xe7\xbe\x42\xdc\x3b" +
9651+
"\xdd\xfd\xdd\xf8\x3b\x00\x00\xff\xff\x72\x8d\xa6\xef")
96529652

96539653
var _file_12 = &file{
96549654
fileInfo: &fileInfo{
96559655
name: "list.html",
96569656
isDir: false,
9657-
size: 3288,
9657+
size: 3285,
96589658
mode: os.FileMode(0),
96599659
mTime: time.Unix(-62135596800, 0),
96609660
cType: "text/html; charset=utf-8",

route/exec.go

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,28 @@ import (
1616
)
1717

1818
func (server *Server) handleExec(c *gin.Context, counter *counter) {
19-
cInfo := server.containerCli.GetInfo(c.Request.Context(), c.Param("id"))
20-
server.generateHandleWS(c.Request.Context(), counter, cInfo).
19+
execID := c.Param("id")
20+
containerID, ok := server.getContainerID(execID)
21+
if !ok {
22+
log.Errorf("exec id %s not found", execID)
23+
return
24+
}
25+
26+
server.m.RLock()
27+
masterTTY, ok := server.masters[execID]
28+
server.m.RUnlock()
29+
if ok { // exec ID exist, use the same master
30+
log.Infof("using exist master for exec %s", execID)
31+
server.processShare(c, execID, masterTTY, true)
32+
return
33+
}
34+
35+
cInfo := server.containerCli.GetInfo(c.Request.Context(), containerID)
36+
server.generateHandleWS(c.Request.Context(), execID, counter, cInfo).
2137
ServeHTTP(c.Writer, c.Request)
2238
}
2339

24-
func (server *Server) generateHandleWS(ctx context.Context, counter *counter, container types.Container) http.HandlerFunc {
40+
func (server *Server) generateHandleWS(ctx context.Context, execID string, counter *counter, container types.Container) http.HandlerFunc {
2541
return func(w http.ResponseWriter, r *http.Request) {
2642
if container.Shell == "" {
2743
log.Errorf("cannot find a valid shell in container [%s]", container.ID)
@@ -60,7 +76,7 @@ func (server *Server) generateHandleWS(ctx context.Context, counter *counter, co
6076
cctx, timeoutCancel := context.WithCancel(ctx)
6177
defer timeoutCancel()
6278

63-
err = server.processTTY(cctx, timeoutCancel, conn, container)
79+
err = server.processTTY(cctx, execID, timeoutCancel, conn, container)
6480
switch err {
6581
case ctx.Err():
6682
closeReason = "cancelation"
@@ -76,7 +92,7 @@ func (server *Server) generateHandleWS(ctx context.Context, counter *counter, co
7692
}
7793
}
7894

79-
func (server *Server) processTTY(ctx context.Context, timeoutCancel context.CancelFunc,
95+
func (server *Server) processTTY(ctx context.Context, execID string, timeoutCancel context.CancelFunc,
8096
conn *websocket.Conn, container types.Container) error {
8197
arguments, err := server.readInitMessage(conn)
8298
if err != nil {
@@ -133,21 +149,21 @@ func (server *Server) processTTY(ctx context.Context, timeoutCancel context.Canc
133149
// webtty.WithReconnect(10), // not work....
134150
}
135151

136-
wrapper := &wsWrapper{conn}
137152
shareID := fmt.Sprintf("%s-%d", container.ID, time.Now().UnixNano())
138153
masterTTY, err := types.NewMasterTTY(ctx, containerTTY, shareID)
139154
if err != nil {
140155
return err
141156
}
142-
server.mMux.Lock()
143-
if _, ok := server.masters[container.ID]; !ok {
144-
server.masters[container.ID] = masterTTY
145-
}
146-
server.mMux.Unlock()
157+
158+
server.m.Lock()
159+
server.masters[execID] = masterTTY
160+
server.m.Unlock()
161+
147162
defer func() {
148-
server.mMux.Lock()
149-
delete(server.masters, container.ID)
150-
server.mMux.Unlock()
163+
// if master dead, all slaves dead
164+
server.m.Lock()
165+
delete(server.masters, execID)
166+
server.m.Unlock()
151167
}()
152168

153169
if server.options.EnableAudit {
@@ -159,6 +175,7 @@ func (server *Server) processTTY(ctx context.Context, timeoutCancel context.Canc
159175
}
160176

161177
log.Infof("new web tty for container: %s", container.ID)
178+
wrapper := &wsWrapper{conn}
162179
tty, err := webtty.New(wrapper, masterTTY, opts...)
163180
if err != nil {
164181
return fmt.Errorf("failed to create webtty: %s", err)

route/handler.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,25 @@ import (
1616
"github.com/wrfly/container-web-tty/util"
1717
)
1818

19+
func (server *Server) handleExecRedirect(c *gin.Context) {
20+
containerID := c.Param("id")
21+
execID := server.setContainerID(containerID)
22+
c.Redirect(302, "/exec/"+execID)
23+
}
24+
1925
func (server *Server) handleWSIndex(c *gin.Context) {
20-
cInfo := server.containerCli.GetInfo(c.Request.Context(), c.Param("id"))
26+
execID := c.Param("id")
27+
containerID, ok := server.getContainerID(execID)
28+
if !ok {
29+
log.Errorf("exec id %s not found", execID)
30+
return
31+
}
32+
cInfo := server.containerCli.GetInfo(c.Request.Context(), containerID)
2133
titleVars := server.titleVariables(
2234
[]string{"server"},
2335
map[string]map[string]interface{}{
2436
"server": map[string]interface{}{
2537
"containerName": cInfo.Name,
26-
"containerID": cInfo.ID,
2738
},
2839
},
2940
)

route/id.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package route
2+
3+
import "github.com/wrfly/container-web-tty/util"
4+
5+
func (server *Server) getContainerID(execID string) (string, bool) {
6+
server.m.Lock()
7+
containerID, ok := server.execs[execID]
8+
server.m.Unlock()
9+
return containerID, ok
10+
}
11+
12+
func (server *Server) setContainerID(containerID string) string {
13+
execID := util.ID(containerID)
14+
server.m.Lock()
15+
server.execs[execID] = containerID
16+
server.m.Unlock()
17+
return execID
18+
}

route/route.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ type Server struct {
3232
srv *http.Server
3333
hostname string
3434

35+
// execID -> containerID
36+
execs map[string]string
37+
// execID -> process
3538
masters map[string]*types.MasterTTY
36-
mMux sync.RWMutex
39+
m sync.RWMutex
3740
}
3841

3942
var (
@@ -66,7 +69,7 @@ func init() {
6669
panic(err)
6770
}
6871

69-
titleFormat := "{{ .containerName }} - {{ printf \"%.8s\" .containerID }}@{{ .containerLoc }}"
72+
titleFormat := "{{ .containerName }}@{{ .containerLoc }}"
7073
titleTemplate, err = noesctmpl.New("title").Parse(titleFormat)
7174
if err != nil {
7275
log.Fatal(err)
@@ -92,6 +95,7 @@ func New(containerCli container.Cli, options config.ServerConfig) (*Server, erro
9295
return &Server{
9396
options: options,
9497
containerCli: containerCli,
98+
execs: make(map[string]string, 500),
9599
masters: make(map[string]*types.MasterTTY, 50),
96100
hostname: h,
97101

@@ -136,7 +140,8 @@ func (server *Server) Run(ctx context.Context, options ...RunOption) error {
136140

137141
// exec
138142
counter := newCounter(server.options.IdleTime)
139-
router.GET("/exec/:id/", server.terminalPage)
143+
router.GET("/e/:id/", server.handleExecRedirect) // containerID
144+
router.GET("/exec/:id/", server.terminalPage) // execID
140145
router.GET("/exec/:id/"+"ws", func(c *gin.Context) { server.handleExec(c, counter) })
141146

142147
if server.options.EnableShare {

route/share.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,45 @@ import (
66
"github.com/gin-gonic/gin"
77
"github.com/gorilla/websocket"
88
log "github.com/sirupsen/logrus"
9+
"github.com/wrfly/container-web-tty/types"
910
"github.com/yudai/gotty/webtty"
1011
)
1112

1213
func (server *Server) handleShare(c *gin.Context) {
13-
ctx := c.Request.Context()
14-
cid := c.Param("id")
15-
cInfo := server.containerCli.GetInfo(ctx, cid)
14+
execID := c.Param("id")
15+
server.m.RLock()
16+
masterTTY, ok := server.masters[execID]
17+
server.m.RUnlock()
18+
if !ok || masterTTY == nil {
19+
log.Error("share terminal error, master not found")
20+
return
21+
}
1622

23+
server.processShare(c, execID, masterTTY, server.options.Collaborate)
24+
}
25+
26+
func (server *Server) processShare(c *gin.Context, execID string, masterTTY *types.MasterTTY,
27+
collaborate bool) {
1728
conn, err := server.upgrader.Upgrade(c.Writer, c.Request, nil)
1829
if err != nil {
1930
log.Errorf("upgrade ws error: %s", err)
2031
return
2132
}
2233
defer conn.Close()
23-
2434
// note: must read the init message
2535
// although it's useless in this situation
2636
server.readInitMessage(conn)
2737

28-
server.mMux.RLock()
29-
masterTTY, ok := server.masters[cInfo.ID]
30-
server.mMux.RUnlock()
38+
ctx := c.Request.Context()
39+
containerID, ok := server.getContainerID(execID)
3140
if !ok {
32-
log.Error("share terminal error, master not found")
33-
conn.WriteMessage(websocket.CloseMessage, []byte("master container not found, exit"))
41+
log.Error("share terminal error, exec not found")
42+
conn.WriteMessage(websocket.CloseMessage,
43+
[]byte("exec container not found, exit"))
3444
return
3545
}
3646

47+
cInfo := server.containerCli.GetInfo(ctx, containerID)
3748
titleBuf, err := server.makeTitleBuff(cInfo)
3849
if err != nil {
3950
e := fmt.Sprintf("failed to fill window title template: %s", err)
@@ -42,7 +53,7 @@ func (server *Server) handleShare(c *gin.Context) {
4253
return
4354
}
4455

45-
fork := masterTTY.Fork(ctx, server.options.Collaborate)
56+
fork := masterTTY.Fork(ctx, collaborate)
4657
defer fork.Close()
4758

4859
tty, err := webtty.New(

0 commit comments

Comments
 (0)