| 176 | } |
| 177 | |
| 178 | func (s *DispatchServerV2) invokeHandler(w http.ResponseWriter, r *http.Request) { |
| 179 | conn, _, ok := setupHijackConn(w, r) |
| 180 | if !ok { |
| 181 | logs.Error("setupHijackConn failed") |
| 182 | return |
| 183 | } |
| 184 | defer conn.Close() |
| 185 | |
| 186 | runtimeid := r.Header.Get("x-cfc-runtimeid") |
| 187 | commitid := r.Header.Get("x-cfc-commitid") |
| 188 | // TODO: [improve] hostip here is always 127.0.0.1 |
| 189 | hostip := r.Header.Get("x-cfc-hostip") |
| 190 | logs.V(6).Infof("runtime %s@%s connect", runtimeid, hostip) |
| 191 | |
| 192 | runtime, err := s.runtimeDispatcher.GetRuntime(runtimeid) |
| 193 | if err != nil { |
| 194 | logs.V(3).Errorf("runtime %s not found", runtimeid) |
| 195 | return |
| 196 | } |
| 197 | |
| 198 | warmNotify := make(chan struct{}) |
| 199 | params := &startRuntimeParams{ |
| 200 | commitID: commitid, |
| 201 | hostIP: hostip, |
| 202 | conn: conn, |
| 203 | warmNotify: warmNotify, |
| 204 | urlParams: r.URL.Query(), |
| 205 | } |
| 206 | go func() { |
| 207 | select { |
| 208 | case <-warmNotify: |
| 209 | logs.V(9).Infof("[resource modify]-[increase]: runtime %s, resource %s", runtime.RuntimeID, runtime.Resource) |
| 210 | s.runtimeDispatcher.IncreaseUsedResource(runtime.Resource) |
| 211 | } |
| 212 | }() |
| 213 | if err := runtime.startRuntimeLoop(params); err != nil { |
| 214 | logs.Errorf("init runtime %s failed: %s", runtime.RuntimeID, err.Error()) |
| 215 | return |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | func (s *DispatchServerV2) runnerHandler(w http.ResponseWriter, r *http.Request) { |
| 220 | runtimeID := r.Header.Get("x-cfc-runtimeid") |