Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

implement a garbage-collector for unused reuse connections #73

Merged
merged 3 commits into from
Aug 13, 2019

Conversation

marten-seemann
Copy link
Collaborator

Fixes #70.

This PR implements the sweeper as suggested in #63.

The sweeper runs every 30 seconds and removes connections that have been unused for more than 10 seconds. In order to not leak go routines, it stops itself once a reuse doesn't have any more active connections, and is restarted as soon as a connection is added.

reuse.go Outdated Show resolved Hide resolved
reuse.go Show resolved Hide resolved
reuse.go Show resolved Hide resolved
Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bunch of nits but otherwise LGTM.

reuse.go Outdated Show resolved Hide resolved
func (c *reuseConn) IncreaseCount() { atomic.AddInt32(&c.refCount, 1) }
func (c *reuseConn) DecreaseCount() { atomic.AddInt32(&c.refCount, -1) }
func (c *reuseConn) GetCount() int { return int(atomic.LoadInt32(&c.refCount)) }
func (c *reuseConn) IncreaseCount() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should probably be private.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it actually matters. We're never exporting a reuseConn from this package, so there's no way a user could call this function anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. But can't the user type assert?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really. What we're returning is (wrapped) QUIC connections, not UDP connections.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, fair enough. I still think private functions are clearer but, well, we're not consistent about that anyways.

c.mutex.Unlock()
}

func (c *reuseConn) ShouldGarbageCollect(now time.Time) bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: also should be private.

c.mutex.Unlock()
}

func (c *reuseConn) DecreaseCount() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also should be private.

@marten-seemann marten-seemann merged commit 61a9a79 into master Aug 13, 2019
@marten-seemann marten-seemann deleted the reuse-garbage-collect branch August 13, 2019 04:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

close unused connections
2 participants