go-sciter icon indicating copy to clipboard operation
go-sciter copied to clipboard

fatal error: concurrent map read and map write

Open ibenben opened this issue 5 years ago • 17 comments

Fisrt,I bind click event to the element after SetHtml() code. Then I trigger the click event. After that,the issue show like this:

image

sciter.go:600 image

How can I fix it?

ibenben avatar Oct 29 '18 14:10 ibenben

Do you use goroutines or threads?

pravic avatar Oct 29 '18 15:10 pravic

@pravic I did not. I did the things like these: 1、call SetHtml() function to change the element 2、bind the click event to the element 3、trigger the click event 4、when i trigger the click event,I will back to step 1 and step by step

I did these things many a time,then the issue showed.

ibenben avatar Oct 29 '18 15:10 ibenben

Well, then it's really odd, because Sciter itself runs in a single UI thread, and so do its events that are bound to Go's handlers.

Is it possible to make a minimal code example with this issue?

pravic avatar Oct 29 '18 16:10 pravic

I make the example like this: image image image image

ibenben avatar Oct 30 '18 05:10 ibenben

When I use multiple strings to the SetHtml function,and bind the event after setter the issue may be showed. I think the reason is when the event try to bind to the element ,the html did not load complete. But I do not know how to fix it. Did the SetHtml function has the onLoaded event?

ibenben avatar Oct 30 '18 05:10 ibenben

Oh dear, it'd be really a challenge to OCR your screens.

pravic avatar Oct 30 '18 14:10 pravic

Did the SetHtml function has the onLoaded event?

It can be the CONTENT_CHANGED event.

@c-smile Andrew, could you comment on this issue?

pravic avatar Oct 30 '18 14:10 pravic

When that finalize function is called? What code initiates its call?

c-smile avatar Oct 30 '18 14:10 c-smile

It's called by GC, because of runtime.SetFinalizer, which is registered here:

https://github.com/sciter-sdk/go-sciter/blob/83bc269d88dd706b394eb591ff2702ce93c8eb61/sciter.go#L558-L566

Also its documentations says

A single goroutine runs all finalizers for a program, sequentially.

So it looks like a go-sciter's issue. Perhaps. Because it's never occurred before.

pravic avatar Oct 30 '18 14:10 pravic

@ibenben Your Go version, by the way?

pravic avatar Oct 30 '18 14:10 pravic

@pravic My Go version is 1.11 .

ibenben avatar Oct 31 '18 00:10 ibenben

image

The CONTENT_CHANGED event did not fix the issue. I need some help. @pravic

ibenben avatar Oct 31 '18 08:10 ibenben

image When I use multiple strings to the SetHtml function,and I do not bind the event after setter the issue may also be showed.

ibenben avatar Oct 31 '18 08:10 ibenben

Nice try.

This:

html = "A"; 
for( i = 0; i < 20; ++i ) 
  html += html;

will be a string of length 220

And your code above will try to allocate string of size 4020.

Correction not 4020 but 40 * 220 which is way smaller but still quite large for reasonable HTML - 41,943,040 Mb.

Are we in Halloween contest? Or is this normal, everyday thing in Goland?

c-smile avatar Oct 31 '18 14:10 c-smile

The length of html string in my code is 52428800. Golang permits it.

That is a try.But my issue does not be fixed.

Before the issue is showed,the html string can be loaded. I need some help. @c-smile

I am sorry to bother you. Happy Halloween.

ibenben avatar Oct 31 '18 14:10 ibenben

Golang permits it.

Oh, really? I suspected that google is the only place where magicians still live these days. But even for them to allocate memory chunk of size 1032 could be challenging.

Just for the note number of atoms in Universe is 1078.

c-smile avatar Oct 31 '18 15:10 c-smile

In any case it is not clear who will consume HTML of 52 MB in size.

Just for the note: number of words in "War and Peace" of Leo Tolstoy is 587,287. That will be around 5 MB of characters. User will throw away your app if your show that amount of data to him/her.

So what's the point?

c-smile avatar Oct 31 '18 16:10 c-smile