Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeouts do not work in network sockets #656

Closed
MateuszKlatecki opened this issue Oct 29, 2020 · 4 comments · Fixed by nanoframework/nf-interpreter#1753
Closed

Timeouts do not work in network sockets #656

MateuszKlatecki opened this issue Oct 29, 2020 · 4 comments · Fixed by nanoframework/nf-interpreter#1753

Comments

@MateuszKlatecki
Copy link
Member

Details about Problem

Target: Any

Firmware image version: Latest

Description

Timeouts in network sockets do not work

Detailed repro steps so we can see the same problem

  1. Deploy program below
using System;
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace SocketTest
{
    public class Program
    {
        public static void Main()
        {

            var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
            {
                SendTimeout = 5000,
                ReceiveTimeout = 5000
            };


            IPEndPoint ep = new IPEndPoint(IPAddress.Parse("192.168.3.4"), 502);
            socket.Connect(ep);

            var receiveBuffer = new byte[10];
            try
            {
                socket.Receive(receiveBuffer);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }


            Thread.Sleep(Timeout.Infinite);
        }
    }
}
  1. Assuming the server doesn't send anything, 5 seconds after the Receive method is called, a SocketException should be thrown, but it is not.

Expected behavior

An exception should be properly thrown on a timeout.

@josesimoes
Copy link
Member

Do you know what's causing it?

@MateuszKlatecki
Copy link
Member Author

@MateuszKlatecki MateuszKlatecki self-assigned this Oct 29, 2020
@josesimoes
Copy link
Member

That's the intended behaviour to allow thread execution. Any timeout/error/etc is handled at lwIP layer.
Otherwise all calls would be blocking.

@MateuszKlatecki
Copy link
Member Author

I know this mechanism - it used in many places. But I think timeout should be set to proper value. I think timeout is not passed in the method parameter for no reason. See PR: nanoframework/nf-interpreter#1753

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants