Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

locking between 2 browser tabs #1039

Closed
pgte opened this issue Oct 16, 2017 · 10 comments
Closed

locking between 2 browser tabs #1039

pgte opened this issue Oct 16, 2017 · 10 comments
Assignees
Labels
exp/wizard Extensive knowledge (implications, ramifications) required kind/architecture Core architecture of project kind/bug A bug in existing code (including security flaws) need/maintainers-input Needs input from the current maintainer(s)

Comments

@pgte
Copy link
Contributor

pgte commented Oct 16, 2017

  • Version: latest
  • Platform: browser
  • Subsystem: repo

Type: question

Severity: Medium

Description:

In order to prevent opening the same IPFS node on two different browser tabs, I need to acquire some type of lock. By what I understand, locking in the browser is done in memory, preventing cross-tab access. Is there any way to solve this using js-ipfs?

Steps to reproduce the error:

Not applicable

@dignifiedquire
Copy link
Member

dignifiedquire commented Oct 16, 2017 via email

@pgte
Copy link
Contributor Author

pgte commented Oct 16, 2017

My question was more if js-ipfs allows this somehow, and if it doesn't, does it plan to?

(My opinion is that locking to ensure the same IFPS peerId is not shared between tabs should be a core feature.)

@dignifiedquire
Copy link
Member

Okay, then I am not sure what you are asking, ipfs-repo does locking so you can't reuse the same repo if both instances try to use the same indexddb entry. Are you asking for an exposed api to do locking in user land, or are suggesting js-ipfs should do more locking out of the box?

@daviddias daviddias added status/ready Ready to be worked kind/bug A bug in existing code (including security flaws) exp/wizard Extensive knowledge (implications, ramifications) required help wanted Seeking public contribution on this issue P1 High: Likely tackled by core team if no one steps up labels Oct 17, 2017
@pgte
Copy link
Contributor Author

pgte commented Oct 17, 2017

I guess I'm asking several things:

  • Locking should be done in a shared medium, so the locking can propagate across tabs.
  • Locking should be exposed via an API so that apps can verify whether the lock exists and whether they can acquire it.

Makes sense?

@daviddias
Copy link
Member

@pgte is there a way to share an object across multiple tabs? That way js-ipfs would check if there is another node on start and just use that one.

@pgte
Copy link
Contributor Author

pgte commented Feb 21, 2018

@diasdavid AFAIK, you can only pass messages (probably using localStorage), which means that some locking protocol would have to be built on top of this..

I think that the main problem to solve here is detecting that the lock owner tab is dead. This could be somehow accomplished by the owner putting a unique identifier in local storage that will enable other nodes to verify if the owner tab is alive or not.

Another option is to have temporary locks (5 seconds, for instance), which have to be constantly renewed.

Having said this, if two or more nodes boot up concurrently, there would need to be a way to guarantee that one and only of them wins, which I believe can only be accomplished with a consensus protocol.. I think we cannot escape this, but I may be wrong..

@daviddias
Copy link
Member

daviddias commented Jul 5, 2018

Let's have a session on this during the dev meetings. It is a big question in general, "What to recommend users do when you have multiple tabs of the same domain, web workers, service workers and so on. Who handles the repo and how can we make sure not to be too restrictive (i.e. lock everything) but at the same time not let race conditions or concurrency problems happen"

This is relevant for the Web Browsers work (@lidel), the GUI work (@olizilla), MFS (@achingbrain #1360), the DApps work (@pgte @satazor) and of course for all the js-ipfs users (@alanshaw @hugomrdias).

@alanshaw, @achingbrain, @hugomrdias can I kindly ask you to propose a session around this topic for ipfs/developer-meetings?

@alanshaw
Copy link
Member

alanshaw commented Jul 5, 2018

ipfs-inactive/developer-meetings#19

@hugomrdias hugomrdias added kind/architecture Core architecture of project need/maintainers-input Needs input from the current maintainer(s) and removed P1 High: Likely tackled by core team if no one steps up help wanted Seeking public contribution on this issue status/ready Ready to be worked labels May 21, 2020
@hugomrdias hugomrdias changed the title locking locking between 2 browser tabs May 21, 2020
@hugomrdias
Copy link
Member

@Gozala can you have a look at this issue

MicrowaveDev pushed a commit to galtproject/js-ipfs that referenced this issue May 22, 2020
* fix: response for findpeer and findprovs

Pick out the correct item from the response, do not assume the first is the one we want.

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>

* fix: allow CID instance to be passed

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>

* docs: add comments for magic Type numbers

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>

* fix: reinstate not found error

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>

* fix: module name

* fix: add skip for dht.findprovs timeout test

Go IPFS does not implement this option and the error that was being checked for was a false positive - it was an error to report no providers were found, which is not an error just a fact and this PR fixes this by removing that error and thus causing this test to now fail.

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
@SgtPooki SgtPooki moved this to 🥞 Todo in js-ipfs deprecation May 17, 2023
@whizzzkid whizzzkid assigned achingbrain and unassigned whizzzkid May 24, 2023
@achingbrain
Copy link
Member

js-ipfs is being deprecated in favor of Helia. You can #4336 and read the migration guide.

If this is still an issue I would recommend opening an issue on the Helia repo.

@github-project-automation github-project-automation bot moved this from 🥞 Todo to ✅ Done in js-ipfs deprecation Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
exp/wizard Extensive knowledge (implications, ramifications) required kind/architecture Core architecture of project kind/bug A bug in existing code (including security flaws) need/maintainers-input Needs input from the current maintainer(s)
Projects
No open projects
Status: Done
Development

No branches or pull requests

7 participants