Could not connect to SAFE Network


#1

initSAFE error: -2000: Unexcpected (probably a logic error): Could not connect to the SAFE Network
This error appear sometime when I reload the webpage in Peruse Browser and then I need to reopen the browser. Frequently encountered this is quite annoying. Why is it happening and is there any way to solve it?


#2

This can happen if there’s a problem with resources not being freed (the number of connections to the proxy) which I’ve encountered recently.

You can read more about this in the following topic - note that in my last reply there I’m convinced there is still a browser or SAFE API bug at play here even after Gabriel’s fix.


#3

Hi @JackTiew, can you please share which webpage/webapp you are experiencing this with?
Also can you please confirm which version of the browser you were having this issue with?

As @happybeing explained, we put some fix in our latest version 10.0.2 (https://github.com/maidsafe/safe_browser/releases/tag/0.10.2) related to this type of issue, so it’ll be good if you share that info with us to try to reproduce it.


#4

I’m using peruse v0.5.3. I am just using localhost to test my webpage.


#5

Ok, can you please try with the latest version of Beaker browser I mentioned above?


#6

It’s just happen sometime…I will let you know if the error coming out again using the Beaker browser.


#7

@bochaco Previously I am using Peruse Browser and localhost to test my webpages. Can the Beaker browser that you suggest can also run with localhost? I’ve tried to open and its fine when loading HTML/CSS file. However, when I start to use SAFE API like window.safeApp.initialise(appInfo) it shows me this error:
TypeError: Cannot read property 'initialise' of undefined
Why is this happen?


Webapp quick start tutorial,Cannot read property 'initialise' of undefined
#8

It’s just that in beaker the way to access localhost is different, i.e. localhost://p:<port> is beaker while this would be localhost:<port> in Peruse.


#9

After using the Beaker browser, the same problem appear and it’s now happen the error every time when it’s running window.safeApp.connectAuthorised. Previously the Peruse browser happen only sometimes.


#10

I suggest you publish some code (on alpha2) which has this problem so others can look into it for you.


#11
//Document loaded
$( document ).ready(function()
{
	console.log( "Webpage finish loading!" )
	SafeInit();
});

async function SafeInit() { 
	console.log('Authorizing web application from Safeshop')
	localStorage['mdEntries'] = null 

	try {
		//Remember to change back!!!
	    const app_info = {
			name: 'test', //SafeShop
			id: 'test', //SafeShop.SAFE.Alpha2
			version: '1.0',
			vendor: 'tester' //Jack
	    }

	    //Asking to have these permissions
	    const access = {
	    	_public: ['Read', 'Insert', 'Update', 'Delete'],
	    	_publicNames: ['Read', 'Insert', 'Update', 'Delete'],
	    }
	    const options = { own_container: true }

	    //Retrieving SafeShop token
	    localStorage["AppToken"] = await window.safeApp.initialise(app_info)
	    console.log("Application Token received:", localStorage["AppToken"]);

	    //Waiting for user authorization
	    if(localStorage["auth_uri"]===undefined) {
		    console.log("Waiting for user authorization...")
		    localStorage["auth_uri"] = await window.safeApp.authorise(localStorage["AppToken"], access, options)
		    console.log("Application was authorised by user.")

		    //Auth URI received from user
		    console.log('Auth URI received: ' + localStorage["auth_uri"])
		}    

	    //Connect using app token and auth URI
	    await window.safeApp.connectAuthorised(localStorage["AppToken"], localStorage["auth_uri"])
	    
	    // obtain handle to container
	    console.log()
	    localStorage['ContainerMDhandle'] = await window.safeApp.getContainer(localStorage["AppToken"], SAFE_containerName)    
	   
	    // get container MD entries
	    localStorage['mdEntries'] = await window.safeMutableData.getEntries(localStorage['ContainerMDhandle'])

	    if(!localStorage['mdEntries']) {
			window.alert('safeMutableData.getEntries returns nothing')
			return
		}
		else { //Entires found
			console.log('obtained mdEntries handle: ', localStorage['mdEntries'])
	    }
  	}
  	catch(err) {
	    window.alert('initSAFE error: ' + err)
	    return
	}
}

This is the code I have used. The -2000: Unexcpected (probably a logic error): Could not connect to the SAFE Network happen sometimes in Peruse Browser, but in Beaker Browser it happen every time, which means I can’t test in Beaker Browser at all.

Besides, recently I’ve found out another error -205: IPC error: StringError(Utf8("invalid utf-8: corrupt contents"))


#12

What happens if you change the above to always authorise:

if(true) {


#13

Yes I tried that before, it still has the same error during window.safeApp.connectAuthorised. The if statement is just want to skip the authorize by user every time when they load.


#14

I think you may need to upload the whole thing to alpha 2 then, because I use something similar without such a severe problem. I can get that error reproducably, but not every time and never with localhost (only on alpha2).

Once you have uploaded to alpha 2 others can try it and start to isolate the problem.

Also state which version of each browser you use, how to reproduce the problem, and what happens. If you do that, it can be solved much quicker than posting bits and pieces here because all the information will be in one place.


#15

I only happen the error when I did multiple times change to a MD entries. Your reply let me think of putting these authorise code in a pre-running js file, only redirect to home page when it successful. It might be just a temporary solution but it can reduce the time for me to reopen the browser. Anyway thanks alot!


#16

#17

all – closing off as we seemed to have reached the end.
Jack - if you have more issues let me know.