Megatest

Check-in [d63db5ff94]
Login
Overview
Comment:partially modularized portions of http-transport
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | v1.6569-refactor-server-key-chk-modularization
Files: files | file ages | folders
SHA1: d63db5ff942283014c66700fa3642a9cb162cfed
User & Date: mrwellan on 2021-01-14 16:29:13
Other Links: branch diff | manifest | tags
Context
2021-01-14
16:29
partially modularized portions of http-transport Leaf check-in: d63db5ff94 user: mrwellan tags: v1.6569-refactor-server-key-chk-modularization (unpublished)
14:55
check server-key on every request server gets check-in: f74b755ed8 user: pjhatwal tags: v1.6569-refactor-server-key-chk
Changes

Modified http-transport.scm from [2c6cca5ae0] to [b8e37f093a].

233
234
235
236
237
238
239


























































240
241
242
243
244
245
246
  (set! *http-connections-next-cleanup* (+ (current-seconds) 10))
  (mutex-unlock! *http-mutex*))

(define (http-transport:inc-requests-and-prep-to-close-all-connections)
  (mutex-lock! *http-mutex*)
  (set! *http-requests-in-progress* (+ 1 *http-requests-in-progress*)))



























































;; Send "cmd" with json payload "params" to serverdat and receive result
;;
(define (http-transport:client-api-send-receive run-id serverdat cmd params #!key (numretries 3)(area-dat #f))
  (let* ((fullurl    (if (vector? serverdat)
			 (http-transport:server-dat-get-api-req serverdat)
			 (begin
			   (debug:print 0 *default-log-port* "FATAL ERROR: http-transport:client-api-send-receive called with no server info")







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
  (set! *http-connections-next-cleanup* (+ (current-seconds) 10))
  (mutex-unlock! *http-mutex*))

(define (http-transport:inc-requests-and-prep-to-close-all-connections)
  (mutex-lock! *http-mutex*)
  (set! *http-requests-in-progress* (+ 1 *http-requests-in-progress*)))

(module httpclientmod
*

(import scheme
	http-client
	chicken
	srfi-18
	extras
	)

(defstruct srr ;; send-receive-rec
  (res #f)
  (success #f))

(define (srr-send-receive srrobj db:string->obj db:obj->string *http-mutex* debug:debug-mode debug:print debug:print-info *default-log-port* remote-conndat-set!)
  (mutex-lock! *http-mutex*)
  ;; (condition-case (with-input-from-request "http://localhost"; #f read-lines)
  ;;					       ((exn http client-error) e (print e)))
  (set! res (vector                ;;; DON'T FORGET - THIS IS THE CLIENT SIDE! NOTE: consider moving this to client.scm since we are only supporting http transport at this time.
	     success
	     (db:string->obj 
	      (handle-exceptions
		  exn
		(let ((call-chain (get-call-chain))
		      (msg        ((condition-property-accessor 'exn 'message) exn)))
		  (set! success #f)
                  (if (debug:debug-mode 3)
                      (debug:print-info 0 *default-log-port* "couldn't talk to server, trying again ...")
                      (begin
                        (debug:print 0 *default-log-port* "WARNING: failure in with-input-from-request to " fullurl ".")
                        (debug:print 0 *default-log-port* " message: " msg ", exn=" exn)
                        (debug:print 0 *default-log-port* " cmd: " cmd " params: " params " key:" (or server-id "thekey"))
                        (debug:print 0 *default-log-port* " call-chain: " call-chain)))
                  (if runremote
		      (remote-conndat-set! runremote #f))
		  ;; Killing associated server to allow clean retry.")
		  ;; (tasks:kill-server-run-id run-id)  ;; better to kill the server in the logic that called this routine?
		  (mutex-unlock! *http-mutex*)
					     ;;; (signal (make-composite-condition
					     ;;;          (make-property-condition 'commfail 'message "failed to connect to server")))
					     ;;; "communications failed"
		  (db:obj->string #f))
		(with-input-from-request ;; was dat
		 fullurl 
		 (list (cons 'key (or server-id "thekey"))
		       (cons 'cmd cmd)
		       (cons 'params sparams))
		 read-string))
	      transport: 'http)
             0)) ;; added this speculatively
  ;; Shouldn't this be a call to the managed call-all-connections stuff above?
  (close-all-connections!)
  (mutex-unlock! *http-mutex*)
  )

) ;; module end
(import httpclientmod)

;; Send "cmd" with json payload "params" to serverdat and receive result
;;
(define (http-transport:client-api-send-receive run-id serverdat cmd params #!key (numretries 3)(area-dat #f))
  (let* ((fullurl    (if (vector? serverdat)
			 (http-transport:server-dat-get-api-req serverdat)
			 (begin
			   (debug:print 0 *default-log-port* "FATAL ERROR: http-transport:client-api-send-receive called with no server info")
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
       (max-retry-attempts 1)
       ;; consider all requests indempotent
       (retry-request? (lambda (request)
			 #f))
       ;; send the data and get the response
       ;; extract the needed info from the http data and 
       ;; process and return it.
       (let* ((send-recieve (lambda ()
			      (mutex-lock! *http-mutex*)
			      ;; (condition-case (with-input-from-request "http://localhost"; #f read-lines)
			      ;;					       ((exn http client-error) e (print e)))
			      (set! res (vector                ;;; DON'T FORGET - THIS IS THE CLIENT SIDE! NOTE: consider moving this to client.scm since we are only supporting http transport at this time.
					 success
					 (db:string->obj 
					  (handle-exceptions
					      exn
					      (let ((call-chain (get-call-chain))
						    (msg        ((condition-property-accessor 'exn 'message) exn)))
						(set! success #f)
                                                (if (debug:debug-mode 3)
                                                    (debug:print-info 0 *default-log-port* "couldn't talk to server, trying again ...")
                                                    (begin
                                                      (debug:print 0 *default-log-port* "WARNING: failure in with-input-from-request to " fullurl ".")
                                                      (debug:print 0 *default-log-port* " message: " msg ", exn=" exn)
                                                      (debug:print 0 *default-log-port* " cmd: " cmd " params: " params " key:" (or server-id "thekey"))
                                                      (debug:print 0 *default-log-port* " call-chain: " call-chain)))
                                                (if runremote
						    (remote-conndat-set! runremote #f))
						;; Killing associated server to allow clean retry.")
						;; (tasks:kill-server-run-id run-id)  ;; better to kill the server in the logic that called this routine?
						(mutex-unlock! *http-mutex*)
					     ;;; (signal (make-composite-condition
					     ;;;          (make-property-condition 'commfail 'message "failed to connect to server")))
					     ;;; "communications failed"
						(db:obj->string #f))
					    (with-input-from-request ;; was dat
					     fullurl 
					     (list (cons 'key (or server-id "thekey"))
						   (cons 'cmd cmd)
						   (cons 'params sparams))
					     read-string))
					  transport: 'http)
                                         0)) ;; added this speculatively
			      ;; Shouldn't this be a call to the managed call-all-connections stuff above?
			      (close-all-connections!)
			      (mutex-unlock! *http-mutex*)
			      ))
	      (time-out     (lambda ()
			      (thread-sleep! 45)
			      (debug:print 0 *default-log-port* "WARNING: send-receive took more than 45 seconds!!")
			      #f))
	      (th1 (make-thread send-recieve "with-input-from-request"))
	      (th2 (make-thread time-out     "time out")))
	 (thread-start! th1)







|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







319
320
321
322
323
324
325
326







































327
328
329
330
331
332
333
       (max-retry-attempts 1)
       ;; consider all requests indempotent
       (retry-request? (lambda (request)
			 #f))
       ;; send the data and get the response
       ;; extract the needed info from the http data and 
       ;; process and return it.
       (let* ((send-recieve (srr-send-receive srrobj db:string->obj db:obj->string *http-mutex* debug:debug-mode debug:print debug:print-info *default-log-port* remote-conndat-set!))







































	      (time-out     (lambda ()
			      (thread-sleep! 45)
			      (debug:print 0 *default-log-port* "WARNING: send-receive took more than 45 seconds!!")
			      #f))
	      (th1 (make-thread send-recieve "with-input-from-request"))
	      (th2 (make-thread time-out     "time out")))
	 (thread-start! th1)