stopAgent stops the agent process gracefully.
()
| 1125 | |
| 1126 | // stopAgent stops the agent process gracefully. |
| 1127 | func (a *AgentClient) stopAgent() { |
| 1128 | a.mu.Lock() |
| 1129 | defer a.mu.Unlock() |
| 1130 | if a.agentCancel != nil { |
| 1131 | a.agentCancel() |
| 1132 | a.agentCancel = nil |
| 1133 | } |
| 1134 | |
| 1135 | if a.agentCmd != nil && a.agentCmd.Process != nil { |
| 1136 | pid := a.agentCmd.Process.Pid |
| 1137 | a.logger.Debug("Stopping keploy agent", zap.Int("pid", pid)) |
| 1138 | } |
| 1139 | |
| 1140 | // If PTY is active, close it to unblock stdin/stdout copies |
| 1141 | if a.agentPTY != nil { |
| 1142 | // Use the utils function to gracefully stop PTY |
| 1143 | if err := agentUtils.StopPTYCommand(a.agentPTY, a.logger); err != nil { |
| 1144 | a.logger.Debug("failed to stop PTY command", zap.Error(err)) |
| 1145 | } |
| 1146 | } |
| 1147 | } |
| 1148 | |
| 1149 | // monitorAgent monitors the agent process and handles cleanup |
| 1150 | func (a *AgentClient) monitorAgent(clientCtx context.Context, agentCtx context.Context) { |
no test coverage detected