Skip to content

Sync from unknown peer hangs for a minute before erroring despite context timeout #134

@masih

Description

@masih

When syncing from an unknown peer via data transfer, it seems there is some internal timeout of 1 minute, which blocks the sync for at least that amount before it fails despite a lower context timeout.

sync handler failed: datatransfer failed: QmZEmr3pn1KwXrir8PqVigFyA1wxiDeR4xSihWiFB12ZnT-QmUBmx3ZNXkiaeyJQRpVWFWQhsSWPHZocwmYiD9GoxJjLy-1653577315589764001: timed out waiting 1m0s for Accept message from remote peer

Test to reproduce it:

package legs_test

import (
	"context"
	"github.com/filecoin-project/go-legs"
	"github.com/filecoin-project/go-legs/dtsync"
	"testing"
	"time"

	"github.com/filecoin-project/go-legs/test"
	"github.com/ipfs/go-datastore"
	dssync "github.com/ipfs/go-datastore/sync"
	"github.com/libp2p/go-libp2p"
	"github.com/stretchr/testify/require"
)

func TestDTSync_FromUnknownPeerShouldFails(t *testing.T) {
	const topic = "testtopic"
	pubh, err := libp2p.New()
	require.NoError(t, err)
	defer pubh.Close()
	pubds := dssync.MutexWrap(datastore.NewMapDatastore())
	publs := test.MkLinkSystem(pubds)
	pub, err := dtsync.NewPublisher(pubh, pubds, publs, topic)
	require.NoError(t, err)
	defer pub.Close()

	subh, err := libp2p.New()
	require.NoError(t, err)
	defer pubh.Close()
	subds := dssync.MutexWrap(datastore.NewMapDatastore())
	subls := test.MkLinkSystem(subds)
	sub, err := legs.NewSubscriber(subh, subds, subls, testTopic, nil)
	require.NoError(t, err)
	defer sub.Close()

	someCid, err := test.RandomCids(1)
	require.NoError(t, err)

	ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
	defer cancel()
	_, err = sub.Sync(ctx, pubh.ID(), someCid[0], nil, nil)
	require.Error(t, err)
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions