{"action":"created","issue":{"url":"https://api.github.com/repos/sdogruyol/kemal/issues/30","labels_url":"https://api.github.com/repos/sdogruyol/kemal/issues/30/labels{/name}","comments_url":"https://api.github.com/repos/sdogruyol/kemal/issues/30/comments","events_url":"https://api.github.com/repos/sdogruyol/kemal/issues/30/events","html_url":"https://github.com/sdogruyol/kemal/issues/30","id":120769410,"number":30,"title":"Kemal is not thread-safe because HTTP::Server#listen isn't threadsafe","user":{"login":"ilatif","id":1183802,"avatar_url":"https://avatars.githubusercontent.com/u/1183802?v=3","gravatar_id":"","url":"https://api.github.com/users/ilatif","html_url":"https://github.com/ilatif","followers_url":"https://api.github.com/users/ilatif/followers","following_url":"https://api.github.com/users/ilatif/following{/other_user}","gists_url":"https://api.github.com/users/ilatif/gists{/gist_id}","starred_url":"https://api.github.com/users/ilatif/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ilatif/subscriptions","organizations_url":"https://api.github.com/users/ilatif/orgs","repos_url":"https://api.github.com/users/ilatif/repos","events_url":"https://api.github.com/users/ilatif/events{/privacy}","received_events_url":"https://api.github.com/users/ilatif/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":24,"created_at":"2015-12-07T13:04:25Z","updated_at":"2015-12-10T11:41:33Z","closed_at":null,"body":"I have been trying hard to remove env. And while doing that I found out that Kemal is not thread-safe .\r\nBecause HTTP::Server is not thread-safe by-default.\r\nI have found a way to make it thread-safe by using most established technique i.e. creating a process for each incoming request.\r\nThis will not only make Kemal thread-safe which will be beneficial for us in future, but it will allow us to assign context as global variable and we can use that global variable everywhere like redirect, render.\r\nWe can also expose params as a method and this will completely eliminate need of having env.params.\r\n\r\nI discovered this thread-safety issue while creating a global variable in requests. I was putting some sleep in requests as well to notice the behaviour of that global variable. And to my expectation, it did what I was anticipating. I stored content-type as text/plain for one of the requests in a global variable but due to sharing of global variable among all requests, it was being applied to all requests.\r\nI tried the exact same thing with new forked-based server implementation and that issue vanished .\r\nPlease let me know what you think about this? "},"comment":{"url":"https://api.github.com/repos/sdogruyol/kemal/issues/comments/163586730","html_url":"https://github.com/sdogruyol/kemal/issues/30#issuecomment-163586730","issue_url":"https://api.github.com/repos/sdogruyol/kemal/issues/30","id":163586730,"user":{"login":"waterlink","id":609046,"avatar_url":"https://avatars.githubusercontent.com/u/609046?v=3","gravatar_id":"","url":"https://api.github.com/users/waterlink","html_url":"https://github.com/waterlink","followers_url":"https://api.github.com/users/waterlink/followers","following_url":"https://api.github.com/users/waterlink/following{/other_user}","gists_url":"https://api.github.com/users/waterlink/gists{/gist_id}","starred_url":"https://api.github.com/users/waterlink/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/waterlink/subscriptions","organizations_url":"https://api.github.com/users/waterlink/orgs","repos_url":"https://api.github.com/users/waterlink/repos","events_url":"https://api.github.com/users/waterlink/events{/privacy}","received_events_url":"https://api.github.com/users/waterlink/received_events","type":"User","site_admin":false},"created_at":"2015-12-10T11:41:33Z","updated_at":"2015-12-10T11:41:33Z","body":"Then as a next step, you can add a forking web-server on top of the `kemal`, maybe even as a separate library. And provide it as a default dependency."}}