Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复日志循环打印问题 #151

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions pkg/jms/poll.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/jumpserver/kael/pkg/schemas"
"github.com/jumpserver/wisp/protobuf-go/protobuf"
"go.uber.org/zap"
"io"
)

type PollJMSEvent struct{}
Expand All @@ -29,8 +28,6 @@ func (p *PollJMSEvent) clearZombieSession() {
resp, err := grpc.GlobalGrpcClient.Client.ScanRemainReplays(ctx, req)
if err != nil || !resp.Status.Ok {
logger.GlobalLogger.Error("Failed to scan remain replay")
} else {
logger.GlobalLogger.Info("Scan remain replay success")
}
}

Expand All @@ -40,18 +37,17 @@ func (p *PollJMSEvent) waitForKillSessionMessage() {
logger.GlobalLogger.Error("dispatch task err", zap.Error(err))
return
}
waitChan := make(chan struct{})
logger.GlobalLogger.Info("start dispatch task success")

closeStreamChan := make(chan struct{})
for {
taskResponse, err := stream.Recv()
if err == io.EOF {

if err != nil {
_ = stream.CloseSend()
close(waitChan)
close(closeStreamChan)
break
}
if err != nil {
logger.GlobalLogger.Error("Failed to receive a note", zap.Error(err))
continue
}

task := taskResponse.Task
sessionId := task.SessionId
Expand All @@ -75,7 +71,8 @@ func (p *PollJMSEvent) waitForKillSessionMessage() {
}
}
}
<-waitChan
<-closeStreamChan
p.waitForKillSessionMessage()
}
func (p *PollJMSEvent) sendFinishTask(stream protobuf.Service_DispatchTaskClient, TaskId string) {
req := &protobuf.FinishedTaskRequest{
Expand All @@ -101,7 +98,7 @@ func (p *PollJMSEvent) sendSessionState(jmss *JMSSession, state schemas.SessionS
response := &schemas.AskResponse{
Type: schemas.Waiting,
ConversationID: jmss.Session.Id,
SystemMessage: msg,
SystemMessage: msg,
Meta: schemas.ResponseMeta{SessionState: state},
}

Expand Down