Re: [go-nuts] will GC close unused connection ?

2017-02-16 Thread caspian46
Thanks! I'm going to read it carefully.

在 2017年2月16日星期四 UTC+8下午4:40:54,Konstantin Khomoutov写道:
>
> On Thu, 16 Feb 2017 00:29:04 -0800 (PST) 
> casp...@gmail.com  wrote: 
>
> > > > Will GC close unused connection ? 
> > > 
> > > No. At least not directly. A finalizer can possibly do that and 
> > > finalizers are possibly invoked by the GC. 
> [...] 
> > Means yes, GC will close unused connection, just indirectly? 
> > Cause I found this: 
> > #/opt/go/src/net/fd_unix.go 
> > func (fd *netFD) setAddr(laddr, raddr Addr) { 
> > fd.laddr = laddr 
> > fd.raddr = raddr 
> > runtime.SetFinalizer(fd, (*netFD).Close) 
> > } 
> > 
> > And this function is called by netFD.dial in sock_posix.go:148 
>
> It means "the runtime _may_ eventually close the connection after the 
> Go's value wrapping it was garbage-collected, but this is not 
> guaranteed to happend, and quite likely it will not happen". 
>
> Please read this recent thread [1] dealing with finalizers. 
>
> 1. https://groups.google.com/d/topic/golang-nuts/d8aF4rAob7U/discussion 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] will GC close unused connection ?

2017-02-16 Thread caspian46
Many thanks!
Yes, I know that it is wrong to keep connection without call Close func. 
just when I working on a bug, I found the connection was closed 
automatically somehow.


在 2017年2月16日星期四 UTC+8下午4:33:54,Axel Wagner写道:
>
> Yes, in general, the GC will usually close connections when the 
> corresponding files are collected. But a) you can't really rely on that and 
> b) the number of file descriptors that a program can open is very limited 
> and for many programs, the rate at which they are opened is high enough, 
> that they will pass that threshold, because the GC doesn't collect them 
> quickly enough.
>
> Given how limited file descriptors are, you thus should still take care to 
> actually close all files you open yourself.
>
> On Thu, Feb 16, 2017 at 9:29 AM,  wrote:
>
>> Thanks for you reply!
>> Means yes, GC will close unused connection, just indirectly?  Cause I 
>> found this:
>> #/opt/go/src/net/fd_unix.go
>> func (fd *netFD) setAddr(laddr, raddr Addr) {
>> fd.laddr = laddr
>> fd.raddr = raddr
>> runtime.SetFinalizer(fd, (*netFD).Close)
>> }
>>
>> And this function is called by netFD.dial in sock_posix.go:148
>>
>>
>> 在 2017年2月16日星期四 UTC+8下午3:31:07,Jan Mercl写道:
>>>
>>> On Thu, Feb 16, 2017 at 8:20 AM  wrote:
>>>
>>> > Will GC close unused connection ?
>>>
>>> No. At least not directly. A finalizer can possibly do that and 
>>> finalizers are possibly invoked by the GC.
>>>
>>> -- 
>>>
>>> -j
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] will GC close unused connection ?

2017-02-16 Thread Konstantin Khomoutov
On Thu, 16 Feb 2017 00:29:04 -0800 (PST)
caspia...@gmail.com wrote:

> > > Will GC close unused connection ?
> >
> > No. At least not directly. A finalizer can possibly do that and
> > finalizers are possibly invoked by the GC.
[...]
> Means yes, GC will close unused connection, just indirectly?
> Cause I found this:
> #/opt/go/src/net/fd_unix.go
> func (fd *netFD) setAddr(laddr, raddr Addr) {
> fd.laddr = laddr
> fd.raddr = raddr
> runtime.SetFinalizer(fd, (*netFD).Close)
> }
> 
> And this function is called by netFD.dial in sock_posix.go:148

It means "the runtime _may_ eventually close the connection after the
Go's value wrapping it was garbage-collected, but this is not
guaranteed to happend, and quite likely it will not happen".

Please read this recent thread [1] dealing with finalizers.

1. https://groups.google.com/d/topic/golang-nuts/d8aF4rAob7U/discussion

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] will GC close unused connection ?

2017-02-16 Thread 'Axel Wagner' via golang-nuts
Yes, in general, the GC will usually close connections when the
corresponding files are collected. But a) you can't really rely on that and
b) the number of file descriptors that a program can open is very limited
and for many programs, the rate at which they are opened is high enough,
that they will pass that threshold, because the GC doesn't collect them
quickly enough.

Given how limited file descriptors are, you thus should still take care to
actually close all files you open yourself.

On Thu, Feb 16, 2017 at 9:29 AM,  wrote:

> Thanks for you reply!
> Means yes, GC will close unused connection, just indirectly?  Cause I
> found this:
> #/opt/go/src/net/fd_unix.go
> func (fd *netFD) setAddr(laddr, raddr Addr) {
> fd.laddr = laddr
> fd.raddr = raddr
> runtime.SetFinalizer(fd, (*netFD).Close)
> }
>
> And this function is called by netFD.dial in sock_posix.go:148
>
>
> 在 2017年2月16日星期四 UTC+8下午3:31:07,Jan Mercl写道:
>>
>> On Thu, Feb 16, 2017 at 8:20 AM  wrote:
>>
>> > Will GC close unused connection ?
>>
>> No. At least not directly. A finalizer can possibly do that and
>> finalizers are possibly invoked by the GC.
>>
>> --
>>
>> -j
>>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] will GC close unused connection ?

2017-02-16 Thread caspian46
Thanks for you reply!
Means yes, GC will close unused connection, just indirectly?  Cause I found 
this:
#/opt/go/src/net/fd_unix.go
func (fd *netFD) setAddr(laddr, raddr Addr) {
fd.laddr = laddr
fd.raddr = raddr
runtime.SetFinalizer(fd, (*netFD).Close)
}

And this function is called by netFD.dial in sock_posix.go:148


在 2017年2月16日星期四 UTC+8下午3:31:07,Jan Mercl写道:
>
> On Thu, Feb 16, 2017 at 8:20 AM  wrote:
>
> > Will GC close unused connection ?
>
> No. At least not directly. A finalizer can possibly do that and finalizers 
> are possibly invoked by the GC.
>
> -- 
>
> -j
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] will GC close unused connection ?

2017-02-15 Thread Jan Mercl
On Thu, Feb 16, 2017 at 8:20 AM  wrote:

> Will GC close unused connection ?

No. At least not directly. A finalizer can possibly do that and finalizers
are possibly invoked by the GC.

-- 

-j

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.