Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
laddr DialTimeout <> DialTCP
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Paul van Brouwershaven  
View profile  
 More options Sep 7 2012, 4:39 am
From: Paul van Brouwershaven <p...@vanbrouwershaven.com>
Date: Fri, 7 Sep 2012 01:39:33 -0700 (PDT)
Local: Fri, Sep 7 2012 4:39 am
Subject: laddr DialTimeout <> DialTCP

Hi,

I implemented DialTimeout on a TLS connection and trying to define my
source (laddr) address. In previous versions of Go this was possible with
the laddr option in the Dial command, now this option is only available in
DialTCP but that function does not have a timeout option.

Any ideas how I can make a TLS connection from a defined laddr with a
timeout?

    // Configure a timeout of 15 seconds
    ipConn, errDial := net.DialTimeout("tcp", "www.google.com:443",
15*time.Second)
    config := tls.Config{ServerName: "www.google.com"}
    conn := tls.Client(ipConn, &config)
    defer conn.Close()

    // TLS Handshake
    errHandshake := conn.Handshake()

Thanks,

Paul


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jingcheng Zhang  
View profile  
 More options Sep 7 2012, 4:45 am
From: Jingcheng Zhang <dio...@gmail.com>
Date: Fri, 7 Sep 2012 16:45:25 +0800
Local: Fri, Sep 7 2012 4:45 am
Subject: Re: [go-nuts] laddr DialTimeout <> DialTCP
You can write it by yourself. Here is my code:

func TcpDial(localAddress string, remoteAddress string, timeout
time.Duration) (*net.TCPConn, error) {
    timer := time.NewTimer(timeout)
    defer timer.Stop()

    type Result struct {
        *net.TCPConn
        error
    }
    channel := make(chan *Result, 1)
    go func() {
        var localAddr, remoteAddr *net.TCPAddr
        var err error
        var tcpConn *net.TCPConn

        if localAddress != "" {
            localAddr, err = net.ResolveTCPAddr("tcp", localAddress)
            if err != nil {
                goto finished
            }
        }
        remoteAddr, err = net.ResolveTCPAddr("tcp", remoteAddress)
        if err != nil {
            goto finished
        }
        tcpConn, err = net.DialTCP("tcp", localAddr, remoteAddr)
        if err != nil {
            goto finished
        }
    finished:
        channel <- &Result{TCPConn: tcpConn, error: err}
    }()
    select {
    case <-timer.C:
        return nil, errors.New("connect timeout")
    case result := <-channel:
        if result.error != nil {
            return nil, result.error
        }
        return result.TCPConn, nil
    }
    panic("unreachable")

}

On Fri, Sep 7, 2012 at 4:39 PM, Paul van Brouwershaven

--
Best regards,
Jingcheng Zhang
Beijing, P.R.China

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paul van Brouwershaven  
View profile  
 More options Sep 7 2012, 5:08 am
From: Paul van Brouwershaven <p...@vanbrouwershaven.com>
Date: Fri, 7 Sep 2012 02:08:27 -0700 (PDT)
Local: Fri, Sep 7 2012 5:08 am
Subject: Re: [go-nuts] laddr DialTimeout <> DialTCP

Thanks, you code looks good, this would be a simple solution.

I see your code looks a like the original DialTimeout where the following
comment is listed:

   121          // TODO(bradfitz): the timeout should be pushed down into the   122             // net package's event loop, so on timeout to dead hosts we   123               // don't have a goroutine sticking around for the default of   124              // ~3 minutes.

So this basically means that the goroutine keeps running and the TCP
session keeps open. Is there a way to kill the goroutine and linked TCP
session?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paul van Brouwershaven  
View profile  
 More options Sep 7 2012, 5:56 am
From: Paul van Brouwershaven <p...@vanbrouwershaven.com>
Date: Fri, 7 Sep 2012 02:56:43 -0700 (PDT)
Local: Fri, Sep 7 2012 5:56 am
Subject: Re: [go-nuts] laddr DialTimeout <> DialTCP

I found issue 2631 that is mentioning this comment.

It looks like the inefficiency in the handling timeouts is not high on the
priority list (Priority-Later).

http://code.google.com/p/go/issues/detail?id=2631


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jingcheng Zhang  
View profile  
 More options Sep 7 2012, 6:02 am
From: Jingcheng Zhang <dio...@gmail.com>
Date: Fri, 7 Sep 2012 18:02:37 +0800
Local: Fri, Sep 7 2012 6:02 am
Subject: Re: [go-nuts] laddr DialTimeout <> DialTCP
On Fri, Sep 7, 2012 at 5:08 PM, Paul van Brouwershaven

<p...@vanbrouwershaven.com> wrote:
> I see your code looks a like the original DialTimeout where the following
> comment is listed:

Yeah, I "steal" the idea from Brad's DialTimeout() implementation :p

>    121             // TODO(bradfitz): the timeout should be pushed down into the
>    122             // net package's event loop, so on timeout to dead hosts we
>    123             // don't have a goroutine sticking around for the default of
>    124             // ~3 minutes.

> So this basically means that the goroutine keeps running and the TCP session
> keeps open. Is there a way to kill the goroutine and linked TCP session?

I'm worrying about this too. Maybe Brad will have an idea :)

--
Best regards,
Jingcheng Zhang
Beijing, P.R.China


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paul van Brouwershaven  
View profile  
 More options Sep 7 2012, 6:27 am
From: Paul van Brouwershaven <p...@vanbrouwershaven.com>
Date: Fri, 7 Sep 2012 03:27:14 -0700 (PDT)
Local: Fri, Sep 7 2012 6:27 am
Subject: Re: [go-nuts] laddr DialTimeout <> DialTCP

It's not only worrying me. I have crashed several routers because
to-many open sessions.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »