Giter VIP home page Giter VIP logo

Comments (7)

kylege avatar kylege commented on May 24, 2024 1

Yes, i'm experience a hang larger than TrackerStopTimeout.

It's not the stopping torrent's PerioidAnnouncer that hangs, it's other running torrents's PerioidAnnouncer hang because of udp tracker.

All announcers share the same udptracker.Transport in TrackerManager

type TrackerManager struct {
	httpTransport *http.Transport
	udpTransport  *udptracker.Transport
}

And there is one lock in udptracker.Transport

func (t *Transport) getConnection(addr string) *connection {
	t.m.Lock()
	defer t.m.Unlock()
	conn, ok := t.connections[addr]
	if !ok {
		conn = new(connection)
		t.connections[addr] = conn
	}
	return conn
}

So when we get lock and hang in Transport.retryTransaction, then another torrent call Transport.getConnection will hang too.

func (t *Transport) retryTransaction(ctx context.Context, f func(*transaction), trx *transaction) ([]byte, error) {
         // this hang until udp tracker done
        // before that, all other torrents call getConnection will hang because of this lock
	t.m.Lock()
	t.transactions[trx.ID()] = trx
	t.m.Unlock()
...
}

And yes, the stopping torrent's announcer.NewStopAnnouncer will hang for a long time, that's what i'm experiencing

Maybe i'm wrong, but please check anyway, thanks.

from rain.

cenkalti avatar cenkalti commented on May 24, 2024 1

I think I get this. I have a solution in my mind. I'll try to implement this weekend.

from rain.

cenkalti avatar cenkalti commented on May 24, 2024

When stopping a torrent, in order to prevent this scenario, first, PerioidAnnouncers are stopped. This operation does not block.

t.stopPeriodicalAnnouncers()

The torrent goes into Stopping state.

Then, another Announcer is started that will only announce one time, with a timeout of TrackerStopTimeout which is 5 seconds by default (but configurable via config file). This is required to tell the tracker that we are stopping the torrent and tell it to remove our client from the peer list.

t.stoppedEventAnnouncer = announcer.NewStopAnnouncer(trackers, t.announcerFields(), t.session.config.TrackerStopTimeout, t.announcersStoppedC, t.log)

This still does not hang. If you don't want to wait for last announce, you can call Torrent.Stop() again to stop it immediately.

Do you experience a hang larger than TrackerStopTimeout?

from rain.

kylege avatar kylege commented on May 24, 2024

I think I get this. I have a solution in my mind. I'll try to implement this weekend.

Hi @cenkalti ,is there any progress?

from rain.

cenkalti avatar cenkalti commented on May 24, 2024

Sorry, I didn't have enough time. I'll try to look again this weekend.

from rain.

cenkalti avatar cenkalti commented on May 24, 2024

Hey @kylege . This issue turned out to be a larger refactor rather that a small fix. I removed the lock completely and replaced it with a goroutine in UDP transport. I already merged it after testing on my own seedbox but feel free to comment and ask questions on the commit: 3321278

Please let me know what do you think. Cheers!

from rain.

kylege avatar kylege commented on May 24, 2024

Hey @kylege . This issue turned out to be a larger refactor rather that a small fix. I removed the lock completely and replaced it with a goroutine in UDP transport. I already merged it after testing on my own seedbox but feel free to comment and ask questions on the commit: 3321278

Please let me know what do you think. Cheers!

Nice work! Problem solved perfectly.

from rain.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.