Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zc2638 committed Jan 14, 2024
1 parent fec3f00 commit 98cd1c8
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 10 deletions.
10 changes: 9 additions & 1 deletion core/clients/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ package clients
import (
"context"
"errors"
"fmt"
"io"
"net/http"
"net/url"
"strconv"
"strings"

"github.com/go-resty/resty/v2"

Expand All @@ -45,11 +48,16 @@ func handleClientError(resp *resty.Response, err error) error {
return err
}
if resp.StatusCode() >= http.StatusBadRequest {
body := resp.String()
b, err := io.ReadAll(resp.RawBody())
if err != nil {
return fmt.Errorf("read body error failed: %v", err)
}
body := strings.TrimSpace(string(b))
errStr, err := strconv.Unquote(body)
if err != nil {
errStr = body
}

switch errStr {
case constant.ErrNoRecord.Error():
return constant.ErrNoRecord
Expand Down
5 changes: 4 additions & 1 deletion core/clients/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,10 @@ func (c *serverV1) LogWatch(ctx context.Context, namespace, name string, number,
logCh := make(chan *livelog.Line)
errCh := make(chan error)
go func() {
sseParser := sse.NewParser(resp.RawBody())
body := resp.RawBody()
defer body.Close()

sseParser := sse.NewParser(body)
err = sseParser.ReadEventLoop(func(message *sse.Message, err error) error {
select {
case <-ctx.Done():
Expand Down
5 changes: 0 additions & 5 deletions core/handler/server/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package server

import (
"context"
"fmt"
"io"
"net/http"
"strconv"
Expand Down Expand Up @@ -116,7 +115,6 @@ func logWatch() http.HandlerFunc {
}
if closeCh == nil {
// TODO step pending 时 livelog 未创建,导致 close nil 的处理
wrapper.InternalError(w, "already closed")
return
}

Expand All @@ -130,12 +128,9 @@ func logWatch() http.HandlerFunc {
go func() {
select {
case <-ctx.Done():
fmt.Println("============= Context Done =============")
case <-sender.WaitForClose():
fmt.Println("============= Sender Done =============")
case <-closeCh:
errCh <- io.EOF
fmt.Println("============= Watch Close =============")
}
}()
_ = sse.SendLoop[*livelog.Line](ctx, sender, lineCh, errCh)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/zc2638/ink
go 1.21.0

require (
github.com/99nil/gopkg v0.0.0-20240114061414-5c020efdb0c4
github.com/99nil/gopkg v0.0.0-20240114071414-7dc8bfdd19e5
github.com/docker/distribution v2.8.2+incompatible
github.com/docker/docker v24.0.5+incompatible
github.com/docker/go-units v0.5.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
gioui.org v0.0.0-20210308172011-57750fc8a0a6/go.mod h1:RSH6KIUZ0p2xy5zHDxgAM4zumjgTw83q2ge/PI+yyw8=
github.com/99nil/gopkg v0.0.0-20240114061414-5c020efdb0c4 h1:a200oSwBJf8X8dBfWLXs09cD0MBFIOoqAqvd2BY5/4k=
github.com/99nil/gopkg v0.0.0-20240114061414-5c020efdb0c4/go.mod h1:yQy7Xa2r1VHYfgqfCuDE6VGDmBt8xJgDVTZ2Bw3xTW0=
github.com/99nil/gopkg v0.0.0-20240114071414-7dc8bfdd19e5 h1:sYpx9nb+ihnkXed2Ow+0bHo0B4OkoyM3P835MarqQ2I=
github.com/99nil/gopkg v0.0.0-20240114071414-7dc8bfdd19e5/go.mod h1:yQy7Xa2r1VHYfgqfCuDE6VGDmBt8xJgDVTZ2Bw3xTW0=
github.com/AdaLogics/go-fuzz-headers v0.0.0-20210715213245-6c3934b029d8/go.mod h1:CzsSbkDixRphAF5hS6wbMKq0eI6ccJRb7/A0M6JBnwg=
github.com/Azure/azure-pipeline-go v0.2.3/go.mod h1:x841ezTBIMG6O3lAcl8ATHnsOPVl2bqk7S3ta6S6u4k=
github.com/Azure/azure-sdk-for-go v16.2.1+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
Expand Down
4 changes: 4 additions & 0 deletions pkg/livelog/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,5 +254,9 @@ func (f *file) Delete(_ context.Context, id string) error {
return err
}
}

f.mux.Lock()
delete(f.clients, id)
f.mux.Unlock()
return nil
}

0 comments on commit 98cd1c8

Please sign in to comment.