Hi guys. I wonder if anyone can point me to a workaround for this apparent SSL bug in the new 2016 SDK?
After running the following test class for a long time(1hour +) , the SSL connection is no longer possible, and it continually throws an exception every time a subsequent request is made.
public static void Main()
{
GHI.Networking.EthernetENC28J60 ethernet = new GHI.Networking.EthernetENC28J60(SPI.SPI_module.SPI1,G120.P1_21,G120.P2_21, G120.P1_21, 1000);
ethernet.EnableDhcp();
ethernet.EnableDynamicDns();
ethernet.Open();
while (ethernet.IPAddress == "0.0.0.0")
{
Thread.Sleep(1000);
}
Utility.SetLocalTime(new DateTime(2016, 03, 30, 10, 58, 01)); // set the time so that SSL works correctly
for (; ; )
{
try
{
string url = "https://httpbin.org/"; // this can be any https site
using (var req = System.Net.HttpWebRequest.Create(url))
{
req.Method = "Get";
using (var res = req.GetResponse())
{
Debug.Print("HTTP Response length: "
+ res.ContentLength.ToString());
using (StreamReader reader = new StreamReader(res.GetResponseStream()))
{
while (reader.Read() > 0)
{ }
}
}
}
}
catch (Exception e)
{
Debug.Print("Fail");
}
}
}
The behavior is much worse when trying to use the Cellular module than with Ethernet, but it occurs in both cases.
below is the exception: ( one thing I noticed is that each time the garbage collector runs, the memory goes up, so I wonder if its a memory leak?). Initially, it executes fine for a while, but then it gets worse and worse until eventually all I get is exceptions.
HTTP Response length: 166
GC: 8msec 7119216 bytes used, 220452 bytes available
Type 0F (STRING ): 2136 bytes
Type 11 (CLASS ): 16140 bytes
Type 12 (VALUETYPE ): 552 bytes
Type 13 (SZARRAY ): 7884 bytes
Type 01 (BOOLEAN ): 24 bytes
Type 03 (U1 ): 4692 bytes
Type 04 (CHAR ): 624 bytes
Type 07 (I4 ): 60 bytes
Type 0F (STRING ): 24 bytes
Type 11 (CLASS ): 2376 bytes
Type 12 (VALUETYPE ): 84 bytes
Type 15 (FREEBLOCK ): 220452 bytes
Type 16 (CACHEDBLOCK ): 720 bytes
Type 17 (ASSEMBLY ): 33084 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 168 bytes
Type 1B (DELEGATE_HEAD ): 360 bytes
Type 1D (OBJECT_TO_EVENT ): 96 bytes
Type 1E (BINARY_BLOB_HEAD ): 7050108 bytes
Type 1F (THREAD ): 1536 bytes
Type 20 (SUBTHREAD ): 192 bytes
Type 21 (STACK_FRAME ): 1860 bytes
Type 22 (TIMER_HEAD ): 72 bytes
Type 27 (FINALIZER_HEAD ): 864 bytes
Type 31 (IO_PORT ): 108 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 3216 bytes
HTTP Response length: 166
GC: 7msec 7130508 bytes used, 209160 bytes available
Type 0F (STRING ): 1884 bytes
Type 11 (CLASS ): 12108 bytes
Type 12 (VALUETYPE ): 552 bytes
Type 13 (SZARRAY ): 5196 bytes
Type 01 (BOOLEAN ): 24 bytes
Type 03 (U1 ): 2004 bytes
Type 04 (CHAR ): 624 bytes
Type 07 (I4 ): 60 bytes
Type 0F (STRING ): 24 bytes
Type 11 (CLASS ): 2376 bytes
Type 12 (VALUETYPE ): 84 bytes
Type 15 (FREEBLOCK ): 209160 bytes
Type 16 (CACHEDBLOCK ): 96 bytes
Type 17 (ASSEMBLY ): 33084 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 168 bytes
Type 1B (DELEGATE_HEAD ): 360 bytes
Type 1D (OBJECT_TO_EVENT ): 96 bytes
Type 1E (BINARY_BLOB_HEAD ): 7069524 bytes
Type 1F (THREAD ): 1536 bytes
Type 20 (SUBTHREAD ): 192 bytes
Type 21 (STACK_FRAME ): 1860 bytes
Type 22 (TIMER_HEAD ): 72 bytes
Type 27 (FINALIZER_HEAD ): 336 bytes
Type 31 (IO_PORT ): 108 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 3216 bytes
HTTP Response length: 166
HTTP Response length: 166
GC: 7msec 7206024 bytes used, 133644 bytes available
Type 0F (STRING ): 1920 bytes
Type 11 (CLASS ): 12684 bytes
Type 12 (VALUETYPE ): 552 bytes
Type 13 (SZARRAY ): 5580 bytes
Type 01 (BOOLEAN ): 24 bytes
Type 03 (U1 ): 2388 bytes
Type 04 (CHAR ): 624 bytes
Type 07 (I4 ): 60 bytes
Type 0F (STRING ): 24 bytes
Type 11 (CLASS ): 2376 bytes
Type 12 (VALUETYPE ): 84 bytes
Type 15 (FREEBLOCK ): 133644 bytes
Type 16 (CACHEDBLOCK ): 192 bytes
Type 17 (ASSEMBLY ): 33084 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 168 bytes
Type 1B (DELEGATE_HEAD ): 360 bytes
Type 1D (OBJECT_TO_EVENT ): 96 bytes
Type 1E (BINARY_BLOB_HEAD ): 7143876 bytes
Type 1F (THREAD ): 1536 bytes
Type 20 (SUBTHREAD ): 192 bytes
Type 21 (STACK_FRAME ): 1860 bytes
Type 22 (TIMER_HEAD ): 72 bytes
Type 27 (FINALIZER_HEAD ): 408 bytes
Type 31 (IO_PORT ): 108 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 3216 bytes
Failed allocation for 1480 blocks, 17760 bytes
#### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (1) ####
#### Message:
#### Microsoft.SPOT.Net.Security.SslNative::SecureConnect [IP: 0000] ####
#### Microsoft.SPOT.Net.Security.SslStream::Authenticate [IP: 0060] ####
#### Microsoft.SPOT.Net.Security.SslStream::AuthenticateAsClient [IP: 000c] ####
#### System.Net.HttpWebRequest::EstablishConnection [IP: 0247] ####
#### System.Net.HttpWebRequest::SubmitRequest [IP: 0019] ####
#### System.Net.HttpWebRequest::GetResponse [IP: 000c] ####
#### Ethernet.Program::Main [IP: 007e] ####
#### SocketException ErrorCode = 1
GC: performing heap compactionâŚ
#### SocketException ErrorCode = 1
A first chance exception of type âSystem.Net.Sockets.SocketExceptionâ occurred in Microsoft.SPOT.Net.Security.dll
#### SocketException ErrorCode = 1
#### SocketException ErrorCode = 1
#### SocketException ErrorCode = 1
#### SocketException ErrorCode = 1
A first chance exception of type âSystem.Net.Sockets.SocketExceptionâ occurred in System.Net.Security.dll
#### SocketException ErrorCode = 1
#### SocketException ErrorCode = 1
#### Exception System.Net.WebException - 0x00000000 (1) ####
#### Message:
#### System.Net.HttpWebRequest::GetResponse [IP: 00c8] ####
#### Ethernet.Program::Main [IP: 007e] ####
A first chance exception of type âSystem.Net.WebExceptionâ occurred in System.Http.dll
Fail
GC: 6msec 7229568 bytes used, 110100 bytes available
Type 0F (STRING ): 1884 bytes
Type 11 (CLASS ): 12108 bytes
Type 12 (VALUETYPE ): 552 bytes
Type 13 (SZARRAY ): 5196 bytes
Type 01 (BOOLEAN ): 24 bytes
Type 03 (U1 ): 2004 bytes
Type 04 (CHAR ): 624 bytes
Type 07 (I4 ): 60 bytes
Type 0F (STRING ): 24 bytes
Type 11 (CLASS ): 2376 bytes
Type 12 (VALUETYPE ): 84 bytes
Type 15 (FREEBLOCK ): 110100 bytes
Type 17 (ASSEMBLY ): 33084 bytes
Type 18 (WEAKCLASS ): 48 bytes
Type 19 (REFLECTION ): 168 bytes
Type 1B (DELEGATE_HEAD ): 360 bytes
Type 1D (OBJECT_TO_EVENT ): 96 bytes
Type 1E (BINARY_BLOB_HEAD ): 7168656 bytes
Type 1F (THREAD ): 1536 bytes
Type 20 (SUBTHREAD ): 192 bytes
Type 21 (STACK_FRAME ): 1860 bytes
Type 22 (TIMER_HEAD ): 72 bytes
Type 27 (FINALIZER_HEAD ): 360 bytes
Type 31 (IO_PORT ): 108 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 3216 bytes
Failed allocation for 1467 blocks, 17604 bytes
#### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (1) ####
#### Message:
#### Microsoft.SPOT.Net.Security.SslNative::SecureConnect [IP: 0000] ####
#### Microsoft.SPOT.Net.Security.SslStream::Authenticate [IP: 0060] ####
#### Microsoft.SPOT.Net.Security.SslStream::AuthenticateAsClient [IP: 000c] ####
#### System.Net.HttpWebRequest::EstablishConnection [IP: 0247] ####
#### System.Net.HttpWebRequest::SubmitRequest [IP: 0019] ####
#### System.Net.HttpWebRequest::GetResponse [IP: 000c] ####
#### Ethernet.Program::Main [IP: 007e] ####
#### SocketException ErrorCode = 1
GC: performing heap compactionâŚ
#### SocketException ErrorCode = 1
A first chance exception of type âSystem.Net.Sockets.SocketExceptionâ occurred in Microsoft.SPOT.Net.Security.dll
#### SocketException ErrorCode = 1
#### SocketException ErrorCode = 1
#### SocketException ErrorCode = 1
#### SocketException ErrorCode = 1
A first chance exception of type âSystem.Net.Sockets.SocketExceptionâ occurred in System.Net.Security.dll
#### SocketException ErrorCode = 1
#### SocketException ErrorCode = 1
#### Exception System.Net.WebException - 0x00000000 (1) ####
#### Message:
#### System.Net.HttpWebRequest::GetResponse [IP: 00c8] ####
#### Ethernet.Program::Main [IP: 007e] ####
A first chance exception of type âSystem.Net.WebExceptionâ occurred in System.Http.dll
Fail