schollz / cowyo

A feature-rich wiki webserver for minimalists :cow: :speech_balloon:
https://cowyo.com/
MIT License
924 stars 67 forks source link

Malformed JSON #70

Closed pasodoff closed 6 years ago

pasodoff commented 7 years ago

Occasionally a page will error with the following stack:

←[31m2017/03/31 13:55:21 [Recovery] panic recovered:
POST /update HTTP/1.1
Host: localhost:8050
Accept: application/json, text/javascript, */*; q=0.01
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.8
Connection: keep-alive
Content-Length: 1720
Content-Type: application/json
Origin: http://localhost:8050
Referer: http://localhost:8050/20170331_Scanning_Solution/edit
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/56.0.2924.87 Safari/537.36
X-Requested-With: XMLHttpRequest

assignment to entry in nil map
/usr/local/go/src/runtime/panic.go:489 (0x42accd)
/usr/local/go/src/runtime/hashmap.go:487 (0x408de0)
/home/zns/go/src/github.com/schollz/versionedtext/versionedtext.go:88 (0x7aef13)

/home/zns/go/src/github.com/schollz/cowyo/page.go:64 (0x81591c)
/home/zns/go/src/github.com/schollz/cowyo/handlers.go:200 (0x810618)
/home/zns/go/src/github.com/gin-gonic/gin/context.go:97 (0x76e281)
/home/zns/go/src/github.com/gin-gonic/gin/recovery.go:45 (0x77daa1)
/home/zns/go/src/github.com/gin-gonic/gin/context.go:97 (0x76e281)
/home/zns/go/src/github.com/gin-gonic/gin/logger.go:72 (0x77cd56)
/home/zns/go/src/github.com/gin-gonic/gin/context.go:97 (0x76e281)
/home/zns/go/src/github.com/gin-gonic/gin/gin.go:284 (0x7746c7)
/home/zns/go/src/github.com/gin-gonic/gin/gin.go:265 (0x773fd2)
/usr/local/go/src/net/http/server.go:2568 (0x6ba2b9)
/usr/local/go/src/net/http/server.go:1825 (0x6b6479)
/usr/local/go/src/runtime/asm_amd64.s:2197 (0x4554f1)
←[0m

Manually reviewing the JSON file shows that it is malformed.

For example the last 3 lines in this case were:

...
}isPrimedForSelfDestruct":false
}
schollz commented 7 years ago

Thanks! I wonder if this is because of simultaneous writing and/or reading - is this your use case? I will try testing this with some load testing tools.

There is no lock currently on reading and writing. I didn't think it would be a problem, since my main use case is for light weight note taking.

schollz commented 7 years ago

@pasodoff I can't figure out how to replicate this error! Let me know if you keep running into it.

pasodoff commented 7 years ago

@schollz. Agreed. I've been using cowyo for personal notes. Single user running locally (hence the other request around specifying localhost ;-) ).

I'm testing again at home now and can't replicate the problem. I'm wondering if it is related to latency in windows roaming profiles where I point the data folder when at work. I'll let you know if I see it again and if I'm able to do some more debugging.

pasodoff commented 7 years ago

@schollz Ok. After a month using Cowyo, I strongly feel this issue is related to a slow network disk. Delayed writes are overwriting a newer successful saves. I have only experience the issue while writing to windows shares (preferred in my case as they are backed up and roam across multiple machines in a corporate environment). I understand if this is out of scope for this tool.

schollz commented 7 years ago

@pasodoff Is it a consistent issue when writing to your windows shares?

I think locks are still a good idea so lets keep this issue open as a reminder to myself to do it!