Edge HTTPS - Maximum number of sockets reached. BUG?

When using HTTPS calls In Edge drivers, it stops working after a number (~250) of calls. Probably the client sockets aren’t closed properly. Seems to be or bug in ssl.https or have I missed a parameter that can solve this issue?
(HTTP doesn’t seem to have this issue, only HTTPS)

Test case to reproduce the issue:

    local https = require('ssl.https')

    local req_num = 1
    for i=1, 256 do
      local res = {}
      local body, code, headers, status = https.request {
        method = 'GET',
        url = 'https://IP',
        data = '',
        protocol = "any",
        options =  {"all"},
        verify = "none",
        sink=ltn12.sink.table(res)
      }
      print('REQ ', req_num, body, code, status)
      req_num = req_num + 1
    end
1 Like

@gol Interesting!

At first glance, I’d say you’re hitting a rate limit, but to have an accurate reference, it would be great if you could share the error log from it.

Also, I’ll take a look at this as well to compare results.

1 Like

@erickv
The output from the code above will not give any error information.
But If run the code below (that should have exactly same functionality), the output is as follow:

2021-10-12T15:33:16.339184636+00:00 TRACE Vanderbilt SPC  Received event with handler TEST START TIMER
2021-10-12T15:33:16.595491761+00:00 PRINT Vanderbilt SPC  1	200	table: 0x13dc930	1
2021-10-12T15:33:16.851645552+00:00 PRINT Vanderbilt SPC  1	200	table: 0x1416038	2
2021-10-12T15:33:17.112338052+00:00 PRINT Vanderbilt SPC  1	200	table: 0x14abf18	3
2021-10-12T15:33:17.374190261+00:00 PRINT Vanderbilt SPC  1	200	table: 0x13faf48	4
2021-10-12T15:33:17.633893844+00:00 PRINT Vanderbilt SPC  1	200	table: 0x13f3fa0	5
2021-10-12T15:33:17.884180969+00:00 PRINT Vanderbilt SPC  1	200	table: 0x13f11f0	6
2021-10-12T15:33:18.139766262+00:00 PRINT Vanderbilt SPC  1	200	table: 0x13e6738	7
2021-10-12T15:33:18.396981757+00:00 PRINT Vanderbilt SPC  1	200	table: 0x1471b80	8
2021-10-12T15:33:18.656031084+00:00 PRINT Vanderbilt SPC  1	200	table: 0x1458680	9
2021-10-12T15:33:18.910229421+00:00 PRINT Vanderbilt SPC  1	200	table: 0x1463530	10
2021-10-12T15:33:19.170377699+00:00 PRINT Vanderbilt SPC  1	200	table: 0x147baa8	11
2021-10-12T15:33:19.466276592+00:00 PRINT Vanderbilt SPC  1	200	table: 0x14c5130	12
....
2021-10-12T15:34:25.218640933+00:00 PRINT Vanderbilt SPC  1	200	table: 0x1467070	248
2021-10-12T15:34:25.487698475+00:00 PRINT Vanderbilt SPC  1	200	table: 0x157adc0	249
2021-10-12T15:34:25.747540891+00:00 PRINT Vanderbilt SPC  1	200	table: 0x15883f0	250
2021-10-12T15:34:26.008275683+00:00 PRINT Vanderbilt SPC  1	200	table: 0x155e928	251
2021-10-12T15:34:26.267942433+00:00 PRINT Vanderbilt SPC  1	200	table: 0x13c0550	252
2021-10-12T15:34:26.525999641+00:00 PRINT Vanderbilt SPC  1	200	table: 0x15ec5a0	253
2021-10-12T15:34:26.783897391+00:00 PRINT Vanderbilt SPC  1	200	table: 0x1503348	254
2021-10-12T15:34:26.790062308+00:00 PRINT Vanderbilt SPC  nil	[string "socket"]:1401: maximum socket count reached	nil	255
2021-10-12T15:34:26.796111516+00:00 PRINT Vanderbilt SPC  nil	[string "socket"]:1401: maximum socket count reached	nil	256

Test code:

local socket = require('socket')
local http = require('socket.http')
local ltn12 = require('ltn12')
local ssl = require('ssl')

driver:call_with_delay(1, function ()
  local try = socket.try
  function create()
    local t = {c = try(socket.tcp())}

    function idx (tbl, key)
      return function (prxy, ...)
         local c = prxy.c
         return c[key](c,...)
      end
    end

    function t:connect(host, port)
      try(self.c:connect(host, port))
      self.c = try(ssl.wrap(self.c,params))
      self.c:sni(host)
      try(self.c:dohandshake())
      return 1
    end
    return setmetatable(t, {__index = idx})
  end

  for i=1, 256 do
    local res = {}
    local b, c, h = http.request {
      url='https://192.X.X.X',
      create = create,
      sink=ltn12.sink.table(res),
    }
    print(b, c, h, i)
  end
end, 'TEST START TIMER')
1 Like

This is an issue we noticed internally too. The fix has been written, but I’m not sure where it is in the release pipeline. I’ll see if I can track that down real quick.

Actually the fix is in the beta release that just went out this morning: Hub Firmware 0.40.X Beta

It was a leak for TLS sockets in general. Though there’s still currently a bug that means the TLS sockets count double against the limit, but once close both of those are uncounted, but you’ll have an effective limit of 128 TLS sockets for the moment.

And thank you for the bug report with a minimal reproduction. Getting those is so immensely helpful.

1 Like

@psbarrett
Good to know that it is a known bug and that there will be a fix eventually.