File tree Expand file tree Collapse file tree 1 file changed +8
-11
lines changed Expand file tree Collapse file tree 1 file changed +8
-11
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ package handlers
2
2
3
3
import (
4
4
"encoding/json"
5
- "fmt"
6
5
"time"
7
6
8
7
"github.com/ChatGPT-Hackers/ChatGPT-API-server/types"
@@ -75,6 +74,7 @@ func API_ask(c *gin.Context) {
75
74
// Find connection with the lowest load and where heartbeat is after last message time
76
75
connectionPool .Mu .RLock ()
77
76
for _ , conn := range connectionPool .Connections {
77
+ println (conn .Id )
78
78
if connection == nil || conn .LastMessageTime .Before (connection .LastMessageTime ) {
79
79
if conn .Heartbeat .After (conn .LastMessageTime ) {
80
80
connection = conn
@@ -90,23 +90,20 @@ func API_ask(c *gin.Context) {
90
90
return
91
91
}
92
92
// Ping before sending request
93
- if ! ping (connection .Id ) {
93
+ println (connection .Id )
94
+ var pingSucceeded bool = ping (connection .Id )
95
+ if ! pingSucceeded {
94
96
// Ping failed. Try again
95
97
connectionPool .Delete (connection .Id )
96
- connectionPool .Mu .RLock ()
97
- for _ , conn := range connectionPool .Connections {
98
- fmt .Println ("Connection ID:" , conn .Id )
99
- }
100
- connectionPool .Mu .RUnlock ()
101
-
102
98
println ("Ping failed" )
99
+ succeeded = false
100
+ connection = nil
103
101
continue
104
102
} else {
105
103
println ("Ping succeeded" )
104
+ succeeded = true
105
+ break
106
106
}
107
- // Ping succeeded. Break the loop
108
- succeeded = true
109
- break
110
107
}
111
108
if ! succeeded {
112
109
// Delete connection
You can’t perform that action at this time.
0 commit comments