1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-11 02:13:49 +09:00

Prevent connections on space deletion

This commit is contained in:
mcrakhman 2023-08-16 21:37:23 +02:00
parent 17a6f7cb55
commit 8b0bb93a2f
No known key found for this signature in database
GPG key ID: DED12CFEF5B8396B
9 changed files with 30 additions and 108 deletions

View file

@ -130,13 +130,12 @@ func (d *diffSyncer) syncWithPeer(ctx context.Context, p peer.Peer) (err error)
err = rpcerr.Unwrap(err)
if err != nil && err != spacesyncproto.ErrSpaceMissing {
if err == spacesyncproto.ErrSpaceIsDeleted {
d.log.Debug("got space deleted while syncing")
d.treeSyncer.SyncAll(ctx, p.Id(), []string{d.storage.SpaceSettingsId()}, nil)
d.syncStatus.SetNodesOnline(p.Id(), syncstatus.RemovedFromNetwork)
}
d.syncStatus.SetNodesOnline(p.Id(), false)
d.syncStatus.SetNodesOnline(p.Id(), syncstatus.ConnectionError)
return fmt.Errorf("diff error: %v", err)
}
d.syncStatus.SetNodesOnline(p.Id(), true)
d.syncStatus.SetNodesOnline(p.Id(), syncstatus.Online)
if err == spacesyncproto.ErrSpaceMissing {
return d.sendPushSpaceRequest(ctx, p.Id(), cl)

View file

@ -262,8 +262,6 @@ func TestDiffSyncer(t *testing.T) {
fx.diffMock.EXPECT().
Diff(gomock.Any(), gomock.Eq(NewRemoteDiff(fx.spaceState.SpaceId, fx.clientMock))).
Return(nil, nil, nil, spacesyncproto.ErrSpaceIsDeleted)
fx.storageMock.EXPECT().SpaceSettingsId().Return("settingsId")
fx.treeSyncerMock.EXPECT().SyncAll(gomock.Any(), mPeer.Id(), []string{"settingsId"}, nil).Return(nil)
require.NoError(t, fx.diffSyncer.Sync(ctx))
})

View file

@ -19,12 +19,10 @@ import (
"github.com/anyproto/any-sync/commonspace/spacestorage"
"github.com/anyproto/any-sync/commonspace/spacesyncproto"
"github.com/anyproto/any-sync/commonspace/syncstatus"
"github.com/anyproto/any-sync/net/peer"
"github.com/anyproto/any-sync/nodeconf"
"github.com/anyproto/any-sync/util/periodicsync"
"github.com/anyproto/any-sync/util/slice"
"go.uber.org/zap"
"golang.org/x/exp/slices"
)
var log = logger.NewNamed(CName)
@ -90,7 +88,7 @@ func (h *headSync) Init(a *app.App) (err error) {
h.syncer = createDiffSyncer(h)
sync := func(ctx context.Context) (err error) {
// for clients cancelling the sync process
if h.spaceIsDeleted.Load() && !h.configuration.IsResponsible(h.spaceId) {
if h.spaceIsDeleted.Load() {
return spacesyncproto.ErrSpaceIsDeleted
}
return h.syncer.Sync(ctx)
@ -118,14 +116,7 @@ func (h *headSync) Run(ctx context.Context) (err error) {
func (h *headSync) HandleRangeRequest(ctx context.Context, req *spacesyncproto.HeadSyncRequest) (resp *spacesyncproto.HeadSyncResponse, err error) {
if h.spaceIsDeleted.Load() {
peerId, err := peer.CtxPeerId(ctx)
if err != nil {
return nil, err
}
// stop receiving all request for sync from clients
if !slices.Contains(h.configuration.NodeIds(h.spaceId), peerId) {
return nil, spacesyncproto.ErrSpaceIsDeleted
}
return nil, spacesyncproto.ErrSpaceIsDeleted
}
return HandleRangeRequest(ctx, h.diff, req)
}