hello everyone,

NIM newbie here, i'm getting "SIGSEGV: illegal storage access" (attempt to read 
from nil?) crash randomly. i have been trying to find what's causing it but i 
can't.

  * i'm building on Windows 7 x64
  * crashing functions seem to be related to std/httpclient
  * it can crash in 1 hour or 1 day randomly without any sign
  * tested both builds x64 and x86 (32bits current)
  * tested on nim-1.6.0 and nim-1.6.10 (32bits current)
  * tested on Win 7 and Win 10 (both crashed)
  * tested also with --mm:arc -d:useMalloc (not sure if it was related, but 
crashed as well)
  * my app logs don't show anything weird coming from the web server (like 
garbage or something similar)
  * i added a timeout at 25000
  * i added the "check_server" function before doing normal get, post, 
download, etc to make sure the server is reachable before the other requests 
(maybe there is a better way to do it)



below are the code snippets i'm using and the crash trace backs' screenshots. 
what's wrong? thank you in advance

<https://imgur.com/a/bdVCJbh> <https://imgur.com/a/SUtjEpa>
    
    
    # GET
    proc http_get_data(params: string): string =
      var obj_response: Response
      
      # CHECK SERVER
      check_server()
      
      var client = newHttpClient(timeout = HTTP_TIMEOUT)
      var full_url = main_server & api_path & "?" & params
      
      try:
        obj_response = client.get(full_url)
      except OSError:
        when DEBUG:
          log_local("[!] http_get_data() FAILED / OSError EXCEPTION RAISED.", 
log_http)
        return ""
      except:
        when DEBUG:
          log_local("[!] http_get_data() FAILED / EXCEPTION RAISED.", log_http)
        return ""
      finally:
        client.close()
      
      if obj_response == nil:
        when DEBUG:
          log_local("[!] http_get_data() NIL RESPONSE/OBJECT EXITING.", 
log_http)
        return ""
      
      var data = obj_response.body
      
      when DEBUG:
        log_local("http_get_data() GET: "&params, log_http)
        log_local("http_get_data() URL: "&full_url, log_http)
        log_local("http_get_data() REPONSE: "&data, log_http)
      
      return data
    
    
    # CHECK SERVER
    proc check_server() =
      var full_url = main_server & api_path & "?id=6"
      var obj_response: Response
      
      while true:
        var client = newHttpClient(timeout = HTTP_TIMEOUT) # 25 seconds
        try:
          obj_response = client.get(full_url)
          if obj_response != nil and obj_response.body == SERVERUP:
            when DEBUG:
              log_local("check_server() HTTP CODE: "&obj_response.status, 
log_server)
              log_local("check_server() HTTP BODY: "&obj_response.body, 
log_server)
              log_local("check_server() SERVER IS UP!", log_server)
            return
        except OSError:
          when DEBUG:
            log_local("[!] SERVER NOT FOUND OR DOWN. RETRYING. OSError 
RAISED.", log_server)
        except:
          when DEBUG:
            log_local("[!] SERVER NOT FOUND OR DOWN. RETRYING. SOME EXCEPTION 
RAISED.", log_server)
        finally:
          client.close()
        
        sleep(3000)
    
    
    Run

Reply via email to