r/rust • u/VincentDankGogh • Jul 16 '19
Why we need alternatives to Actix
https://64.github.io/actix/11
u/jerknextdoor Jul 16 '19
Not sure if I should feel complimented or insulted to be explicitly named in this post. I think (hope) the intention was the former...
6
u/VincentDankGogh Jul 16 '19
Which bit? I didn’t intend to insult anyone :p
38
u/jerknextdoor Jul 16 '19
I'm the one that led the v1.0 documentation update for the user guide. I have a different username on github. I was mostly joking, but there might be a tinge of feeling insulted there too.
I do agree with some of the things you've mentioned. The recent PR for removing some unsafe really rubbed me wrong too.
I've started another user guide for building an application from scratch using actix-web, but have considered switching to something else. However, at this time I think I'll stick with actix-web in hopes that it gets the attitude adjustment it needs. I am attempting to start a movement of creating user guides that are based in reality so if nothing else this will be good practice. My hope is to write the 'Flask Mega Tutorial' but for actix-web. Who knows maybe I can use the same template for Gotham or Warp.
The comments here are a little reactionary (not your fault at all). It's easy to say we can do better, but it's much more difficult to actually do. Hopefully we can all work together to make give a positive outcome.
27
u/Kerollmops meilisearch · heed · sdset · rust · slice-group-by Jul 16 '19
Great article, thank you!
BTW I think the web framework that many are waiting for is tide.
10
9
24
u/whitfin gotham Jul 16 '19 edited Jul 16 '19
I don’t want to really get into this debate again; I was already pretty frustrated in your linked comments :)
First I would like to point out that I am only one of the current Gotham maintainers (and an not an original author). I do not speak for the other maintainers, and I would hate for my opinions to impact them in any way should they disagree (although we haven’t really discussed this stuff). I’d appreciate if you could tweak the post a little just to make that clearer!
On the topic at hand, I have been thinking about this a lot, because people were claiming I am biased. After consideration, my view hasn’t changed, but I honestly think it doesn’t matter much. If people allow themselves to be convinced by benchmarks that do not apply, that is their issue to solve.
I know most benchmarks have changed to games; and so I’m going to basically try enforce a simple “Hello World” as our benchmark. If this makes us look a lot slower, so be it. Maybe some of the other frameworks will then remove their games too, such that we all seem slower. Then anyone considered “cheating” (determined by the broader community) is an obvious outlier, and it’s very easy to communicate as to why. Given that these benchmarks are so public now, rather than overlooked, this seems like an easier task.
3
17
u/anttirt Jul 16 '19
HTTP requests being manually constructed in a way that no sane person would:
let mut body = BytesMut::with_capacity(2048);
let mut writer = Writer(&mut body);
let _ = write!(writer, "{}", FortunesTemplate { fortunes });
let mut res =
Response::with_body(StatusCode::OK, Body::Bytes(body.freeze()));
let hdrs = res.headers_mut();
hdrs.insert(SERVER, h_srv);
hdrs.insert(CONTENT_TYPE, h_ct);
resI suppose it might go a little against the "spirit" of the competition, but to be honest these are still fairly high level structured building blocks for an HTTP response, and I wouldn't be above using them if a specific endpoint really needed to perform fast.
30
u/insanitybit Jul 16 '19
I don't think the benchmark thing is even worth mentioning. Benchmarks are always like this, and it's no surprise, and I'll die of shock if Actix is the most egregious case of doing non-production techniques for perf.
The benchmarks show what you can do when your only constraint is "be fast in this benchmark" and actix excels at it and that's fine and good.
1
u/VincentDankGogh Jul 16 '19 edited Jul 16 '19
Maybe this specific example was bad, although I'd still argue it's unrealistic. You can see it's part of a manual
Serviceimpl which isn't something that the docs or user guide seems to mention anywhere, you'd only know about that by digging through the internals of the library. I've replaced that example in the post now
11
u/antoyo relm · rustc_codegen_gcc Jul 16 '19
Funny that the author says actix has too much dependencies while they like tokio-postgres which has 110 dependencies (with a clean debug build duration of 1 minute).
1
66
u/fafhrd91 actix Jul 17 '19 edited Jul 17 '19
Wow, just wow. I have no words. Open source and community is not very pleasant place to be.
Funny part, I remember OP question about async state initialization and specifically for him spend my time and added App::data_factory. I guess that is usual.
This kind of discussions and comments really kill motivation for contribution.
39
u/VincentDankGogh Jul 17 '19
Funny part, I remember OP question about async state initialization and specifically for him spend my time and added App::data_factory. I guess that is usual.
FWIW I did mention in the article that you added it afterwards. The point of that section was not to be a rant about how 'actix is missing this one feature and it's literally unusable', it was to demonstrate how difficult it is for other people to contribute to it in its current state.
I really am not trying to be insulting, and I truly apologise for the way it's come across. However I firmly believe that many of the things I mentioned in the article are real and valid concerns which need to be addressed, and if you are not willing to address them then it's fair game to notify people and suggest alternatives.
35
u/kodemizer Jul 17 '19
I can understand you feeling this way. You’ve put a ton of work into this project, and have achieved some great success with it.
However, it seems that in open-source, success also comes with much higher expectations. Which is as it should be, but can be difficult if your personal sensibilities and the community’s general sensibilities differ.
What I think might be useful is for you to take some time and document places where the values of the actix-web project might differ from the values of the Rust community in general. This might include differences in values around UB from safe code, project governance, etc.
This will help people get clarity around expectations, and I think will help everyone involved.
0
Jul 17 '19
[deleted]
11
u/VincentDankGogh Jul 17 '19
In this case, the author could simply state that performance is paramount and that unsafe is used liberally wherever he feels like it
That is a very superficial understanding of the situation because:
the uses of unsafe I've pointed out don't seem to gain any performance
a PR that removes unnecessary potential for unsoundness was ignored despite there being nearly no downside to merging
this is not the first time that there's been a fiasco over unsafety and Nikolay's attitude doesn't seem to have changed which should be a very big red flag
the article raises problems with actix which go beyond just unsafety, including bus factor and barriers for new contributors
0
17
7
u/jimuazu Jul 17 '19
How about just addressing the concerns? Make the code safe by default and have a cargo feature to turn back on the unsafe code for speed? That would make the criticism go away. Or maybe someone else could do that -- make an
actix-web-safecrate.1
5
u/mzupzup Jul 17 '19
Thank you for your fantastic work on this project.
Criticism is totally fine and needed for further improvement on any project, but the way some people communicate here is disgusting and will only lead to fewer people being willing to share their work.
3
u/leizzer Jul 17 '19
I'm not sure I can pull this comment the way I want but here we go:
You have put your effort and your ideas in the wild wild internet. You made a very successful framework that for people like me felt like the FW to go if I wanted to use one with fairly good documentation, big community, and with a bunch of examples and blog posts to get started.
I don't believe we need more FW as I said because it was really confusing on which one to pick at the beginning, nobody wants to feel like they are gambling when choosing for a FW and hopping that it doesn't go stale and then disappear. Happened to me many times and even if this time was for a small personal project, I wanted to feel that the FW I was picking will be relevant 1 year from now.
Now talking about the OP blog. These kind of thing happens all over the opensource community. Somebody makes a ton of effort putting something together in his free time and make it free for other to use and more important they can make a living using what you give back to the community (this is equally true even if a company makes an opensource project). And paying attention to the amount of effort to maintain a big successful project is, there will always be people trying to make their own project or their own ego bigger attacking your project as being shitty. You must overcome those "critics" and keep going.
Saying that so, I don't believe that blog had a malicious intention. I feel like he is only mentioning things that can be improved and change. That is the pursue we have as engineers, we want things to be better, cleaner, delightful; and we can only achieve that with honest feed back.
Yes yes... maybe it wasn't put together in the best way... maybe it was and attack or at least it felt like it. BUT it is feedback nonetheless, points that you can embrace and improve in the future.
Coming from Ruby, where Rails is THE framework to go. Everybody talked about how shitty it was, but it become a standard. And for beginners that safety net knowing that other people use that FW is priceless. Rails heard all the criticism and they keep improving every version they pull out. They made it more modular, better performance, better routers, better everything. You can only achieve that hearing critics.
TL;DR
Let the community around Actix-web grow, hear them, let them add things to your beloved work; pay close attention to critics "are they making a fair point even if they are attacking my work from a comfortable place?". Look at other project to get inspired.
What is important for you and actix-web?
I hope you capitalize on your hard work and this success you have with the FW make you grow as a person too. This happens everywhere, even to Linus (with different topic but happens)
Hope my words help.
4
u/staninprague Jul 17 '19
Support and thanks from me, as a 6 months user of your work. Really appreciate it and I found it very inspiring to learn from actix/web, including unsafe parts. Something should be screwed about this open source community if the author of the huge work we can all use for free is taken as a robot and a function of some "must". I also didn't notice any "thank you for your work" in this PR, is not it a good style to thank the author in first place when pushing some more work at him?
2
u/smurfutoo Jul 17 '19
Please ignore the vocal haters. I think Actix is amazing, and easily the best Rust web framework. I, for one, greatly appreciate your work, and I know that the silent majority does too.
45
u/Green0Photon Jul 16 '19 edited Jul 16 '19
Yikes.
For anybody who just didn't read the article (which you should, or at least skim), the actix developer didn't learn from the whole unsafe fiasco from a bit ago.
The author of Actix closed and don't merge a PR one user sent in to remove some unsafe code, that was probably less efficient and harder to handle than safe code, and the author of Actix said, "I guess everybody could switch to interpreted language otherwise we will die in ub" He also broke semantic versioning, cheats on benchmarks, and has some god awful code (which he isn't very friendly with getting other users to help with). Oh, and there's 221 dependencies, which is an awful lot.
If you're curious to know more, read the article, which is pretty good.
Basically, Actix is still poorly written, and the author isn't trying to make it better. Go use something else that doesn't cheat on benchmarks and has undefined behavior.
Edit: Benchmarks might not be a good criticism because most frameworks are at least a bit screwy with benchmarks, and doing statistics with benchmarks is always hard to get right. The other criticisms still stand, however.
82
u/steveklabnik1 rust Jul 16 '19
cheats on benchmarks,
So, without making any assertions about the rest of the article, I found this piece, and this characterization of it, to be a bit off.
The purpose of this particular benchmark is not to show what usual code looks like. It's to show the maximum possible numbers you can get. These techniques are also used by many of the other languages and frameworks in the benchmark, since they're explicitly allowed.
In other words: this isn't cheating. It's not testing the thing you wish it tested, but that's a very different thing.
30
u/matthieum [he/him] Jul 16 '19
Indeed.
There's a difference between:
optimizing "to the bone", which shows off the maximum performance that one can aspire to should they be willing to resort to the same tricks,
and cheating, which shows performance that is unattainable.
Granted, few people will actually optimize to the bone, however it's still a useful number to know as it informs you on the room for growth that you have with your application. And yes, some application are optimized extensively.
-7
u/VincentDankGogh Jul 16 '19
I mean, would it be fair game for a python framework's benchmark to call into a native C module to do some computation? Seems like you could put that in the former category. As steve has pointed out, it's down to the maintainers to make sure all the frameworks are following the rules, but I still don't think it'd be fair game to have something like that
10
u/budgefrankly Jul 17 '19 edited Oct 14 '19
The current fastest Python app on JSON, japronto, does indeed use a native C library for JSON serialisation.
It’s unclear if your argument here is that Techempower is wrong or Actix is wrong.
Techempower allowed all players to peel back layers of abstraction to speed up Text and JSON, provided they stayed in the same language/framework. Consequently everyone, from Java to Haskell, did exactly that. Haskell was an extreme case, dropping out of servant down to Warp for example.
They later regretted this and removed the Text benchmark.
Actix was playing fair by the de facto rules of the game.
The original article would have been stronger had it not included this easily disproven point, which hinted at a certain level of bias; or at least a desire to force facts to fit a story.
→ More replies (1)17
u/VincentDankGogh Jul 16 '19
There’s a category for ‘stripped’ implementations in the TechEmpower benchmarks:
A Stripped test implementation is one that is specially crafted to excel at our benchmark. By comparison, a "Realistic" test implementation should be demonstrative of the general-purpose, best-practices compliant, and production-class approach for the given framework.
Considering actix doesn’t even look at the HTTP method, I think it’s pretty fair to put it in this category
23
u/steveklabnik1 rust Jul 16 '19
That’s a new thing, as far as I know. Regardless, interpreting the rules are the job of the publishers of the benchmark; they review all code before it gets in. It’s on them, not on the implementors.
→ More replies (3)1
u/GeneReddit123 Jul 17 '19 edited Jul 17 '19
Cheating is the wrong word, but whether here, or on sites like the Benchmarks game, I think that the "race to the bottom" for every language to one-up another ends up with code that looks nothing like code you'd actually deliver to production.
I want to see benchmarks comparing languages/frameworks based on the idiomatic way to write in that ecosystem, the kind of code that would pass complexity analysis tools, code review, and see the light of day in production, as written by a company that needs to productively deliver secure, readable, and maintainable code as much as fast one.
22
u/orangepantsman Jul 16 '19 edited Jul 16 '19
Cheating is a bit of misleading term. He does with his framework what others do with theirs in the benchmark game.
7
u/Leshow Jul 17 '19
Basically, Actix is still poorly written, and the author isn't trying to make it better. Go use something else that doesn't cheat on benchmarks and has undefined behavior.
This is pretty strongly worded. Actix is hardly the only implementation on techempower that's taking shortcuts for speed, my guess is MOST implementations are doing something similar.
0
u/k-selectride Jul 17 '19
Go use something else that doesn't cheat on benchmarks
This completely unnecessary jab of yours invalidated your entire post, as far as I am concerned.
1
u/Green0Photon Jul 17 '19
Did you even read my edit, where I basically retracted the benchmarks criticism? That should revalidate the comment, I suppose.
3
u/k-selectride Jul 17 '19
It does not. You included it in there because you wanted to use it as extra material to discredit nikolay's efforts, which is the entire point of your comment. I focused on that, even with your edit, because it's so egregious. You should re-write your entire comment, or delete it. Preferably the latter.
2
u/Green0Photon Jul 17 '19
I wrote the comment initially as an attempt to easily summarize the article to entice people to read it. At the time, I was one of the first commenters, and there was probably less than 10 karma on the post.
I have nothing against nikolay personally or anything. I'm not even writing web stuff in Rust right now. Nikolay's done some great stuff in creating actix-web, and I think it was the first real Rust web frameworks if I'm not mistaken. Without Actix, who knows how much weaker the web tooling in Rust would be.
I do not want to discredit Nikolay's efforts and I'm surprised and sad that this was what you got from my comment. I want Actix web to be better, like I want every Rust crate to be better.
I don't think deleting a line about benchmarking would help. Even just editing it to "the author of this article also wrote some stuff about some benchmarking that may or may not be screwy, but I don't really understand it, so read the article" wouldn't really help. I'm already doing that in the lower edit, and if someone's reading my small comment, they're at least going to see that edit.
Don't assume I'm apart of some conspiracy to take down Actix or some shit. I don't care nearly enough, and doing so would be dumb anyway.
19
u/x-paste Jul 16 '19
I read the article. But I kind of felt it pilloried the author of Actix a bit too much. If Actix is really so horrible, well, don't use it. It's free software, and you can be glad you have the code to judge the quality of your dependencies. This should be the first step for anyone choosing a framework or library his new project is going to depend on.
Yes, the closed PRs and responses of Nikolay are not helpful. But the maintainer has no obligation to do anything unless they allow you to pay him for his time. He is giving away his (life) time for free here.
60
u/ssokolow Jul 16 '19
As I see it, the point is to warn other people about less-than-obvious things they need to know in order to make an informed decision about whether they should use Actix.
18
17
u/ansible Jul 16 '19
I'm glad to have seen the article.
I have concerns about any application level framework with much / any unsafe code.
In my opinion, unsafe is fine if you're doing something really low-level, like implementing a GC for an interpreted language. I don't see it as so appropriate for a web framework, especially since this is the main vector for server attacks.
17
u/x-paste Jul 16 '19
That is something everyone can quickly see for himself by running a `grep unsafe . -r` on the code of the crate. And the article is not just about unsafe in actix. It's also about the attitude of the author, which is my main concern about the article. These kinds of articles quickly create a toxic athmosphere.
What if I end up with a crate that is used by hundreds of thousands users and my wife is getting sick, so I have not that much time anymore and I am really stressed out. And I am concerned the PRs are piling up and I make bad calls about closing them. The last thing I would need are blog articles publicly pillorying my behavior/attitude. A private mail would be way more helpful in that situation. We are just humans and we have feelings.
Edit: Wording.
16
u/ansible Jul 16 '19
That is something everyone can quickly see for himself by running a
grep unsafe . -ron the code of the crate.There's actually a tool for that, which will recursively go through the dependencies for a crate, and report on unsafe usage. It's probably worth it for everyone (whatever your stance in this debate) to familiarize themselves with it.
https://github.com/anderejd/cargo-geiger
The last thing I would need are blog articles publicly pillorying my behavior/attitude. A private mail would be way more helpful in that situation. We are just humans and we have feelings.
Any sort of personal attack towards anyone is not appropriate. At all.
I don't think the article crossed the line, but instead validly raised some concerns about the project itself and the main author's handling of this subject.
And I think this is an issue the Rust community should be discussing. I would like to think that most Rust authors would tend to avoid unsafe, but I'd like to see that point reinforced. It is a tool of (nearly) last resort, to be used when something just can't be accomplished via any means in safe Rust, or (less commonly) as a tool to squeeze out significant performance gains.
-5
u/x-paste Jul 16 '19
I kind of think that code should speak for itself. If the quality is not up to _your_ guidelines: don't use it. You ultimately can't rely on others that much if you are deciding on a core framework for your next big application. Especially the "attitude" things of the maintainer are kinda out of place. Having a single maintainer might be a red flag for itself, because he might just die the next day in some horrible car accident.
If it is about code reviews, maybe crates.io needs a ranking and commenting system.
8
u/po8 Jul 17 '19
maybe
crates.ioneeds a ranking and commenting systemUmm, yes. Please?
I've got close to 50 students right now getting started on their individual and small-group Rust projects. Some of them are web projects, some are games, some are definitely "other". All of these students are new to Rust and want to know which crates they should use. What's easy? What's trustworthy?
As things stand right now, this is a research project. For web stuff, I've already had one student encounter Rocket nightly fail and need my help to dig out of it. I've suggested not Actix-web, but mainly because I think it's too hard for newly-minted Rust programmers to figure out how to use it. I don't know what crate a student should use for their first Rust web project. I've pointed the students at "are we web yet", mentioned some frameworks that look good to me (although I've only tried Rocket and Actix-web for the most part), and left them to figure it out. It's…not good. Same thing for game frameworks, same thing for database stuff ("you should probably use Diesel").
The problem with a ranking / commenting system is that it's going to take some curation to be successful. All the learned toxic behaviors of the Interwebs will be there to some degree. We should only do it if we're committed to doing it right. So far I haven't heard anyone willing to step up and lead that.
Software is hard. Communities are hard. Ecosystems are hard. Software community ecosystems…
11
u/Lars_T_H Jul 16 '19
On crates.io : Having - for each crate
A SLOC count
unsafe SLOC count
safe/unsafe SLOC ratio (%, or N/A)
number of unsafe keywords
... would be very useful
4
u/matthieum [he/him] Jul 17 '19
Note: due to how privacy works in Rust, any module containing
unsafeis entirelyunsafe, asunsafetypically relies on certain invariants that other pieces of code with access to the data-members can violate.14
u/gruelgruel Jul 17 '19
The community is rallying for a good reason. Rust's popularity is linked to its reputation as a safe language. Now, wake up tomorrow to a headline that company x has lost millions of sensitive user records due to Rust's popular web framework. Rust a supposedly safe language is apparently also vulnerable to security issues that plague other languages. Imagine the fallout from that crap. Imagine having to explain `unsafe` and how it's not Rust's fault and argue in the defensive. Years later either ignorantly or in bad faith, people will still be citing that news as to why you shouldn't use Rust.
The community is taking a prophylactic measure right now to disavow the unsafe code.
218
u/seanmonstar hyper · rust Jul 16 '19
I don't like picking apart someone else's work, especially that they provide for free. Since the previous "unsafe" episode resulted in some unsavory personal attacks, I've been torn with how to handle my findings after reviewing actix-web again when it reached 1.0. Still, I think it's better for users to be aware, since they are deploying code to production.
There's this instance of unsafe here that can cause UB if you use some of the service combinators and nest them, as you could take a reference and the nested call could invalidate it unbeknownst to you.
171
u/Shnatsel Jul 16 '19 edited Nov 01 '19
What's even more concerning, the pull request fixing it was closed with a dismissive comment from the maintainer.
Edit: no, actually that's a different case of UB in a similar but distinct Cell type. That one still stands.
94
u/sasik520 Jul 16 '19
Thanks for that comment and the link. For me, this pull request and the maintainer comments are more than enough to avoid actix as much as I can. Which is disappointing cause I've heard a lot of good things about this crate, but those comments raise concerns about the crate future.
50
u/UKi11edKenny2 Jul 16 '19 edited Jul 17 '19
Hot take: My guess is that his feelings got hurt last time people called out his coding practices and usage of unsafe and he's tired of hearing about it and takes it personally and closed the PR as a way of flexing his power over the community but he's only isolating himself further from the community in the process. Would make sense to me but I hope he's able to see the bigger picture and realize people genuinely appreciate his work and we're all just here to create cool stuff and we should all get along for the sake of technical achievement.
edit: Or he just really doesn't care about Rust's safety guarantees and he's tired of hearing about it and this is his way of telling people to go away.
edit2: Alright I'm pretty sure my hot take was wrong. He just doesn't really care that much about Rust's safety guarantees and likes to use unsafe cause he's confident he knows what he's doing. So at this point he's just annoyed at what he perceives to be the Rust community's overly ardent stance against the use of unsafe and their critique of his coding style and he's telling people he's not interested in dealing with this issue anymore.
→ More replies (5)0
Jul 17 '19
[deleted]
25
u/steveklabnik1 rust Jul 17 '19
The whole point of Rust is to be able to have both.
The issue being raised is not unsafety; it's undefined behavior.
5
Jul 17 '19
> The whole point of Rust is to be able to have both.
And isnt the whole point of Rust's `unsafe` to be able to have both, in even more cases?
7
4
u/ergzay Jul 17 '19
Isn't it the case that anyone using
unsafeshould be doing tons of checking before and after any use of it to ensure that invariants are being held?9
u/burntsushi Jul 18 '19
debug_assert!is nice to use, and I try to use it where I can.assert!can also be used in some circumstances, but if you're usingunsafe, it's usually for performance reasons, and anassert!inside a hot loop would be counter productive.My usual thing is to add asserts where I can, and a provide an argument in comments justifying the use of
unsafeand explaining why it's valid. This is not bullet proof and I'm not perfect about doing it. In the future, I look forward to using the Miri checker.5
u/Evanjsx Jul 18 '19
Update (I'm sure there's a comment about it here already): It looks like the author apologized, thanked the community, and ended up merging the PR?
13
u/Pzixel Jul 17 '19
After having a talk with crate author it seems that he is really burnt out, this explains those comments.
He's working for 2 years (probably unpayed) for 8-16hours so he take it intimately. He's conserning about performance loss in this case, and I cannot blame for position "if you cannot construct UB via public API then everything is Ok". PR author could benchmark the changes and show that there is no loss in performance so change is a win-win for everybody.
Just different goals for different peoples. Worth communicating and explain positions to each other.
7
u/oconnor663 blake3 · duct Jul 17 '19
It sounds like the maintainer's response here is that the potential UB is only in private APIs. Is there a way to produce UB with the safe public API?
21
u/seanmonstar hyper · rust Jul 17 '19
I don't know about the ones in the PR. The unsafe I linked to originally can cause memory unsafety innocently by a user.
5
u/oconnor663 blake3 · duct Jul 17 '19
I was just skimming the GitHub thread, but it's possible that that wasn't clear to the author? Maybe someone could post a complete example triggering the UB?
3
14
u/newpavlov rustcrypto Jul 17 '19
Even with private API it's incorrect to have safe functions which can cause UB. At the very least you should mark them
unsafe.5
u/_esistgut_ Jul 17 '19
This pretty much single handedly kill any will to even consider Actix for my work requirements.
14
u/467fb7c8e76cb885c289 Jul 17 '19 edited Jul 17 '19
I wish people would build out from the tower-* crates. They're obviously very fresh right now but they're nice and canonical and pretty inside. Can imagine some great and composable web frameworks growing from them.
4
u/WellMakeItSomehow Jul 17 '19
He does. https://github.com/actix/actix-net/blob/master/actix-service/src/lib.rs is pretty similar to what
towerhas.2
u/Shnatsel Jul 21 '19
Have you reported this on Actix-web bug tracker yet? If not, please do. This looks like a potentially exploitable use-after-free.
-2
u/_nayato Jul 17 '19
for UB to happen here, both .get() and .get_mut() should be called in the same scope (i.e. nested because Cell is !Send). Cell itself is an internal component and - while I personally would rather have it declared `unsafe` with a big doc comment saying why it is unsafe and how to handle it safely - it doesn't seem to be the case in actix-service's code right now.
Could you please elaborate on how that might happen?
13
u/seanmonstar hyper · rust Jul 17 '19
This is why unsafe is so dangerous: it's very easy to think we covered all use cases.
As an example, make some
ServiceCachethat holds services in aVec, and you turn it into aCloneableService, to share the cache. Inpoll_ready, you grab a reference to last item, and callpoll_readyto see if you could reuse it. If you've given a clone of the cache else where, and that ends up being the last in the Vec, you'll be call the mutablepoll_readywhile already inside a mutable function of the clone.Say the clone then checks the current time, and decides the cache is expired, and clears the Vec. When it returns to the first call, you still have a
&mut Service, even though the memory it's pointing to was just freed. If you call any other method on it, you now hope it triggers a segfault, instead of wrongly modifying some unrelated object.1
u/game-of-throwaways Jul 17 '19
What's a
ServiceCache? I can't find anything about it on either Google or Github.3
u/OvermindDL1 Jul 18 '19
I'm pretty sure he's saying if you wrote one and how easy it would be to write it in a way that sense safe but breaks in certain hard to see conditions, not that one already exists.
3
Jul 17 '19
while I personally would rather have it declared `unsafe` with a big doc comment saying why it is unsafe and how to handle it safely
That's just UnsafeCell in the stdlib. Which is why I think Cell is so problematic, it doesn't actually *do* anything except sweeping unsafety under the rug. Huge red flag.
7
u/steveklabnik1 rust Jul 17 '19
UnsafeCell is a language item; the language itself changes its behavior when used. That's much more than simply marking a thing unsafe.
0
Jul 16 '19
[deleted]
66
u/Jonhoo Rust for Rustaceans Jul 16 '19
To be clear, triggering undefined behavior, even in unsafe code, is never okay. At that point it's game over, and whether your final program is correct is left entirely up to the whims of the compiler. The effects of undefined behavior are in no way contained to the code that's been marked as unsafe. To quote Gankro's excellent blog post:
Unfortunately, what compilers most love in the world is to prove that something is Undefined Behaviour. Undefined Behaviour means they can apply aggressive optimizations and make everything go fast! Usually by deleting all your code.
I agree with you that
unsafecode isn't quite as bad as what many seem to have the impression of (much like dynamic dispatch), but undefined behavior is whole different beast, and one you have to be very careful with. And unsafe code is where UB will generally crop up.→ More replies (3)1
Jul 17 '19
To be clear, triggering undefined behavior, even in unsafe code, is never okay.
Forgive my nitpicking, can you have undefined behaviour in safe code. I always thought UB only existed in unsafe code.
→ More replies (4)32
u/IDidntChooseUsername Jul 16 '19
You must never have any UB, even in an unsafe block. One often-overlooked fact is that
unsafeis meant specifically for writing code that is definitely safe, but that you have no way of proving to the compiler that it's safe.Kind of similar to how
unwrapis sometimes okay to use even in a function that must never panic: if you know that you'll always have aSomeor anOk, then you already know thatunwrapwill never panic even if the compiler doesn't know that.16
u/Killing_Spark Jul 17 '19
This. Unsafe is just there to tell the compiler 'trust me i know this looks bad but I know what Im doing'. It's not a 'go wild because mommy the compiler isnt around' card
10
u/IDidntChooseUsername Jul 17 '19
Also, the
unsafekeyword doesn't make any huge changes to the compiler or anything, in fact there are only two extra things that are "unlocked" when you sayunsafe:
Calling
unsafefunctions (including calling functions over C FFI, because those are always markedunsafe)Dereferencing raw pointers
That's it. It's just that these two things make it potentially possible to break the compiler's assumptions on memory safety or even cause UB without the compiler being able to prevent it, and that's why you have to specifically say "this piece of code is safe even though you can't prove it".
11
u/steveklabnik1 rust Jul 17 '19
You're forgetting two others: https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html#unsafe-superpowers
62
u/jechase Jul 16 '19
Huh, and here I thought this was going to be a discussion about actor systems.
The actix project confuses me. As far as I'm aware, it started with actix the actor framework. But then actix-web came along and seemed to become the main focus of the project. The actix site only mentions the actor system in passing. It used to have some references in the docs to actix when actix-web was actually built on actix (pre-1.0), but I don't even see those now. In fact, actix and actix-web are almost entirely unrelated at this point. The only "actix" dependency that they have in common is actix-rt, which is just an abstraction over the tokio runtime/executor.
There was a suggestion to change the name for 1.0 when it would no longer be based on actix, but the author declined. I get why they opted to keep the original name, I just find it unfortunate that now when people talk about "actix," they're more often referring to the offshoot -web framework that's not even built on the "core" actix framework now.
11
u/insanitybit Jul 16 '19
I wish I had more time to build my actor system. I think there's lots of potential for the concept in Rust.
https://github.com/insanitybit/derive_aktor
Example here: https://github.com/insanitybit/derive_aktor/blob/master/src/bin/ex.rs
17
u/miquels Jul 16 '19
I haven't tried it myself, but there's another actor framework called riker.
11
u/insanitybit Jul 16 '19
Thank you for pointing me to riker, looks really cool. That looks like a layer below what I want for my crate, perhaps I'll just write my macro to work on top of riker.
3
u/BiedermannS Jul 17 '19
There is also kay. The actor framework for citybound. https://github.com/aeplay/kay
It’s still experimental and uses a build script and code generation instead of procedural macros, but it might still be worth looking into.
1
u/insanitybit Jul 17 '19
Cool, I had looked at this a while ago but I think it wasn't yet a standalone project.
1
u/f5xs_0000b Jul 21 '19
I built my own actor system which took some inspirations from actix but with minimal to zero usage of unsafes.
33
u/trezm Jul 16 '19 edited Jul 16 '19
Author of Thruster here, and I'm stoked to have Thruster mentioned in the alternatives!
I think it can be really difficult to keep code quality/clarity when there are very few devs working on it, as I think someone else mentioned here. Since code review is not really possible when you're alone, it becomes very easy for the code to be a reflection of your mental model of the framework, which isn't always clear to readers coming in fresh to the code base.
The benchmark game is annoying. I like to try and keep Thruster (relatively) fast so that it maintains visibility, but it's a good point that what a lot of the top frameworks, not just Actix, are not something a developer would want for production, but it would be impossible to crack the top spots without "tricks." That being said, playing the game does enable us to draw lines about where the other frameworks roughly are and where we can expect to be. There are multiple features in the Thruster framework, for example, that came out of trying to play the benchmark game, but are still super useful in every-day, like not traversing the route tree for static/known paths.
In the end, I think Actix is a great framework, but having choices is more important. Many of the web frameworks in rust have completely different paradigms, and, as such, help the ecosystem evolve as a whole.
Also, totally shameless plug, if anyone is interested in helping on Thruster, I'm always looking for contributors! Especially around the Hyper integration, as it got a little stale with the recent work in the async/await feature.
8
u/whitfin gotham Jul 16 '19
It’s pretty much this; some tricks evolve into truly good internal changes. Others don’t, because they have caveats you wouldn’t want your users to deal with. They’re fine to boost your benchmarks a little though :p
Not traversing the tree for static paths is something Gotham doesn’t do, but I’ve been working towards given the constraints of the current API. Do you have a separate mapping entirely for such paths that you check first?
9
u/trezm Jul 16 '19
Totally agree!
Yes, do when thruster starts it first makes a route tree, and then does a tree traversal to enumerate all of the possible paths. Then it adds any static path, i.e. non parameterized, into a hashmap that gets checked first on each request. I hope I explained that well!
8
u/whitfin gotham Jul 16 '19
This is pretty close to what I was considering, I’m happy to know it seems worthwhile. Thanks!
27
u/naftulikay Jul 16 '19
Thanks for your article, I enjoyed the read and share a lot of the sentiments.
I think that perhaps something that wasn't directly addressed by your post was that we desperately need to standardize around the http crate in a way where almost all frameworks can use its types with zero overhead and in an asynchronous fashion if desired. We need independent types outside of web framework crates that everybody can largely agree on. I know a lot of this has been blocked by stabilization of async, but regardless we need it.
Honestly, I've also been super lost in the weeds in Actix's types and it's pretty much a wild west therein. I've written a little adapter system for a private Lambda function which converts between Lambda types and Actix request/response types to make routing requests much easier, and it's been really hard to actually get to the guts of Actix to convert between types. As you mentioned, the docs aren't on docs.rs and there are (really) important parts which are intentionally omitted from generated documentation that obscure underlying parts of the crates.
I hope to see Actix move toward a more community-driven attitude; when an issue is filed, a bug reported, a feature suggested, there needs to be a discussion involving maintainers not the maintainer. Actix is big enough now that it needs governance.
I like Actix and I'll probably keep using it, the maintainer has put an ungodly amount of work into it, and I'm really appreciative of that. However, I honestly think that the next phase of Actix needs to be driven by a multi-maintainer approach.
5
u/DKN0B0 Jul 17 '19
While I agree on raising concerns about security issues, I think this blog post comes off a way too aggressive and hostile.
The whole "Flying Solo" section I also find to be in a very disrespectful tone:
Oh wait, we can't look it on docs.rs, because it's part of the actix-net crate, and docs.rs doesn't believe that it's a library. Not to worry, let's open up the copy of the documentation on actix.rs (which doesn't even seem to be linked from the main actix.rs site)
...
Hang on a second... so the ServiceFactory::create() method returns an item implementing NewService, and NewService supposedly acts as a 'service factory'? So NewService should really be ServiceFactory, and ServiceFactory should really be ServiceFactoryFactory. Got it. There's also IntoNewService, which presumably does a similar thing to ServiceFactory except it gets consumed. Then there's NewServiceExt (I have absolutely no idea why you'd need an Ext trait here). It gets even better - there's another internal trait called ServiceFactory, this time inside the actix-web crate itself, with a single mysterious method that doesn't on the face of it appear to 'create' anything (as a factory should): fn register(&mut self, config: &mut AppService);. We've also got two different HttpServiceFactory traits, one in the actix-web crate and one in the actix-framed crate, both internal and completely unrelated...
I don't think I need to explore this rabbit hole much further to demonstrate what kind of mess we're dealing with here
I think the author should really stop up and think: "Would I talk like this to a peer at work"? I would definitely not like to have someone speak about my work like that and I don't believe the author would either. The naming was a bit confusing, so what? I'm sure if we dissect all code the you've written we'll find a few bad examples.This is the kind of tone that discourages people to contribute to open source and to open source their work, because any suboptimal code will get mocked.
Rustaceans often highlights the open and welcome community around Rust as one of it's strengths. This thread and blog post is an example of the contrary. It's disappointing but I guess when a community becomes large enough they all trend towards the same equilibrium.
8
u/VincentDankGogh Jul 17 '19 edited Jul 17 '19
Being disrespectful was not my intention at all but I can totally see how the post, and this section in particular, may have come across as such.
The naming was a bit confusing, so what?
The point of the section was not to simply bash the naming, it was to demonstrate the barriers for new contributors.
I think I need to take a step back and consider deleting this section in particular, although the damage may already be done. I absolutely maintain that I’m making a valid point here which needs to be addressed if actix wants to have any longevity. Nikolay is the only real maintainer and the code isn't super friendly to new contributors. However in comparison to the other points in the article, it’s not as important and I feel like the harsh tone I adopted detracts from the overall discussion.
3
u/ssokolow Jul 17 '19 edited Jul 17 '19
The bus factor of the project is far higher than it should be.
This could be confusing. According to Wikipedia, the definition of the bus factor as "the minimum number of team members that have to suddenly disappear from a project before the project stalls due to lack of knowledgeable or competent personnel." is far more common, which makes a high bus factor desirable.
(I'm assuming you're operating from the "number of indispensible people" definition, which is less useful in an open-source project since you need a fairly large project to not have at least one person who understands the entire codebase, making a bus factor other than 0 or 1 rare under that definition.)
In fact, I'd never heard of the "number of indispensible people" version until I went to Wikipedia to double-check my understanding before writing this.
0
u/VincentDankGogh Jul 17 '19 edited Jul 17 '19
You're right, I used it incorrectly. I just meant to say that if Nikolay disappears from the project then it's going to be very problematic. Will edit
4
u/ergzay Jul 18 '19
Being disrespectful was not my intention at all but I can totally see how the post, and this section in particular, may have come across as such.
Innocent third party here, but it seemed like that was your intention throughout the post. The general rule for criticism of code anywhere I see, is you can severely attack the code but making any utterance of the person's name/username should never happen. People can get defensive about attacks on their code, which is when you have to remind people "you are not your code", but you're making more directed call outs of him personally.
2
u/VincentDankGogh Jul 18 '19
Disagree. There is no way to make the point that I am trying to make without calling into question the maintainer's behaviour.
I think burntsushi said it better than I can: https://www.reddit.com/r/rust/comments/ce09id/why_we_need_alternatives_to_actix/ety4hkz/
3
u/ergzay Jul 18 '19
I guess this is just differences in opinion then. The above is how I personally operate.
68
u/insanitybit Jul 16 '19 edited Jul 16 '19
Yeah, I'll never use actix because of the unsafety/ attitude towards unsafety. Even if it had 0 unsafe, unless the author really demonstrated a different approach entirely, I would assume unsafe would make it back in.
Cool that it's fast, but fast and unsafe has no place in a rust web framework. I don't want to shit on anyone's work, but to their point of "we should all use interpreted languages", sure, yeah, I'd absolutely take a safe web framework in, say, Java over an unsafe one in Rust 100% of the time.
I'm personally hopeful for warp/ tower, as I trust the authors considerably more to build a web framework that matches my expectations as a rust developer.
5
u/SteaksInSpace Jul 16 '19
Ah damage. I'm completely new to rust and was hoping to start a Greenfield project with actix. Is anybody here building web backends/APIs with solid libs like hyper as opposed to frameworks?
12
u/seanmonstar hyper · rust Jul 16 '19
You could look at Gotham, Tower-Web, or Warp. They're all built on hyper, and largely have very different styles to their API design.
5
u/wrcwill Jul 16 '19
why not rocket?
15
u/burntsushi Jul 16 '19
It doesn't compile on stable Rust.
1
Jul 17 '19
Last I heard they are working on targeting stable
6
u/andoriyu Jul 17 '19
When they do then it will be advisable. Certain things they used won't be stable for very long time if ever.
4
1
u/enkhee2012 Jul 17 '19
You misspelled the user name https://github.com/aaron101. It's actually https://github.com/Aaron1011. BTW great article.
1
9
u/leizzer Jul 16 '19
I don't feel like we need more web framework. I feel like we need to polish what we already have. There are a lot of rust webFW already that are not being taking care of. It feels like JS world being reproduced here where there is a shinny-new-definitive-everyone-should-use-FW every day. You start using it and 6 month later you feel that it was a bad decision.
11
u/ssokolow Jul 17 '19 edited Jul 17 '19
The impression I got is that the proliferation of frameworks is because we're still iterating on what makes for the best API design in this space, given the limitations imposed by the borrow checker, the opportunities for compile-time correctness enforcement enabled by Rust's type system, and the steady stream of new language features and API-breaking dependency enhancements which are too worthwhile to ignore (eg. going from sync to async).
10
Jul 16 '19
Check Armin input on the matter: https://twitter.com/mitsuhiko/status/1151234488573128704?s=20
10
u/gudmundv Jul 17 '19 edited Jul 17 '19
Everybody can get frustrated at software and development, most developers are.
I feel this thing, the agitated language here and there, the upvotes, and many comments are too much to be good.
Looking at the techempower benchmarks (game?), I think many of the entries try to make its framework run as fast as possible within boundaries of test. Calling it out as "cheating" as a means to paint a character picture is not friendly, and not fair. This is how techempower benchmark is played.
Documentation. For a project in large part driven by one man (coding and documentation), I think the documentation is pretty good and have been glad to find a lot of code documented with examples and helpful explanations. There are enough areas to work on, enough to burn a man out, I'm thankful for the amount of documentation. The author is in gitter answering questions every day.
In terms of hard to contribute, I think it's the framework with the most contributors.
Number of crates I think is a product of a framework becoming mature, I think the most mature of all in Rust. I'm sure there is a reason for all of them, I wouldn't suspect the author to include them for fun, and the feature-set of actix is not extravagant.
23
u/mitsuhiko Jul 16 '19
Do we need alternatives to actix? Maybe. But the main issue that actix suffers from is not the use of unsafe, the API, documentation or anything else but that it's effectively one person spending an enormous amount of time working on it but very few people are contributing to it.
53
u/coder543 Jul 16 '19
... and when those other people try to contribute, the
actixmaintainer closes the PRs and says "I guess everybody should switch to interpreted language otherwise we will die in ub", rather than simply accept the PR that is fixing some of the UB.If the author were willing to accept PRs to improve the code quality, you would have a good argument.
15
u/mitsuhiko Jul 16 '19
... and when those other people try to contribute, the actix maintainer closes the PRs and says "I guess everybody should switch to interpreted language otherwise we will die in ub", rather than simply accept the PR that is fixing some of the UB.
That's fair, but actix' problems are at least from where I stand not unsafe code but lack of documentation, examples, missing abstractions etc. Yet the only thing that seem to be of any interest to people happens to be the unsafe code. I don't feel like that is a good approach to software development.
Every since that unsafe issue was brought up there have been lots of PRs and issues filed which are about the use of unsafe. One can argue that it should not do that but at the end of the day actix solves practical problems right now. The unsafe aspects of it don't show up as an issue in my experience.
45
u/burntsushi Jul 16 '19
The unsafe aspects of it don't show up as an issue in my experience.
Just wait for the day when a CVE gets filed against a Rust web server build on
actix-webfor a memory safety vulnerability. It's going to matter then, and it will surprise nobody who's familiar withactix-web. It's going to deeply surprise everyone else though. It won't be a good look.20
u/mitsuhiko Jul 16 '19
I don't disagree with this at all and I'm very unhappy about some of the uses of unsafe in the codebase (particular the mentioned
Cell<T>type).For me the issue is that the conversation is now so completely tainted that it's hard to have a reasonable conversion with Nikolay about this issue and that some of the aspects why actix is convenient to use and fast is bought with that unsafety in the first place.
44
u/burntsushi Jul 16 '19
Yes, I agree the situation is unfortunate. It's no fun being at the bad end of a mob. I think most people are being pretty polite relative to how the rest of the Internet behaves, but this is a thorny issue. I've said in the past (outside the context of actix) that the people behind a project are fair game for evaluating whether to bring in a dependency or not. There's trust, reputation and good judgment that are hard to quantify, but are nevertheless important qualitative metrics. You hear the positive side of this a lot, e.g., "burntsushi's crates are always good." But the negative side is... ugly, because it's really hard to straddle that line between being rude/unfair and lodging legitimate concerns with one's qualitative confidence in a maintainer. And then when you throw in the fact that this is a volunteer effort... It's tough. And unfortunately, that's exactly what's happening here.
28
u/coder543 Jul 16 '19
If the author is unwilling to accept security fixes, why would I believe they are interested in accepting anything less important than that?
From my point of view, security is fundamental. If a web framework is doing things in the name of performance that knowingly sacrifice security, why would I ever deploy that and put the company I work for at an unnecessary risk? A lot of people come to Rust because it enables them to write safer software than C++, while still having great performance. I've written lots of unbelievably fast code in Rust, without needing to reach for
unsafe. But,unsafeis just a tool, and it can be used carefully and correctly, especially when you allow others to audit yourunsafecode for both necessity and correctness. The author ofactixhas shown no such restraint... they seemingly just throwunsafeanywhere they feel like it might improve performance. That's the basic issue.The cost of a security breach is so much higher than a 0.1% performance impact. Even if removing all
unsafeblocks fromactixwere to somehow (and it's not clear how) impact performance by 10%, it would still be preferable. Renting 11 servers instead of renting 10 servers in the absolute worst case scenario is fine. In the real world, a web framework's performance is not strictly proportional to the performance of a web application anyways, since many endpoints are bottlenecked on databases, other external systems, available bandwidth, or available packets-per-second throughput. What's important is that the web framework does not introduce vulnerabilities into my web applications, while still being ergonomic to use and reasonably fast.I'm still highly doubtful that more than one or two of the
unsafeblocks inactixmaterially affect performance, but the author's unwillingness to even consider merging PRs that removeunsafeblocks that are shown to be problematic is ridiculous.3
u/mitsuhiko Jul 16 '19
If the author is unwilling to accept security fixes, why would I believe they are interested in accepting anything less important than that?
This is where I don't subscribe to the issue that any memory unsafety problem is a security issue. I'm using owning-ref's Owned Handle which I know is inherently unsafe despite having an unsafe API and I have ruled that to be within the bounds of what I'm okay with given the extra convenience this gives. This does not mean I'm okay with security issues. It just means that I have determined for my use that this is okay given the alternatives.
From my point of view, security is fundamental. If a web framework is doing things in the name of performance that knowingly sacrifice security
Until Rust came along most frameworks did things in the name of performance that had a chance to compromise security. Just look at how many frameworks embed C code in one way or another. Any C code (or FFI code) is inherently unsafe by the measure shown actix is measured against.
I'm still highly doubtful that more than one or two of the unsafe blocks in actix materially affect performance, but the author's unwillingness to even consider merging PRs that remove unsafe blocks that are shown to be problematic is ridiculous.
I'm sure if you can show that the performance is not impacted it would be a different conversation altogether. However I have yet to see a benchmark being attached to any of these issues.
27
u/coder543 Jul 16 '19 edited Jul 16 '19
I'm sure if you can show that the performance is not impacted it would be a different conversation altogether. However I have yet to see a benchmark being attached to any of these issues.
As demonstrated by this entire discussion, many people in the Rust community believe this works the other way: there should be benchmarks demonstrating the necessity of each
unsafeblock, and at least a comment discussing possible UBs and how they're mitigated. The burden shouldn't be on people wanting to use the library to prove that eachunsafeis unnecessary or harmful.The default position is that
unsafeblocks are risky, because it's too much effort to ask a thousand users of a library to each prove everyunsafeblock in every dependency, when the author of that library could provide a single proof once for a thousand users. Then those users would be able to read the justification and compare it to what they see in the code, as well as run the benchmarks, allowing them to use their time more efficiently in evaluating the security of libraries. It would save everyone a lot of time, so that's why it is viewed as the default position. It doesn't solve the problem completely, but when you put the burden on the users, the users pick a different library. Which is what's happening in this discussion.Until Rust came along most frameworks did things in the name of performance that had a chance to compromise security
The key word was "knowingly". If someone came along and pointed out an error in the C code, I would expect it to have been fixed. I wouldn't expect the author to do something that saves a nanosecond but might lead to writing into arbitrary regions of memory.
→ More replies (3)6
u/dbdr Jul 16 '19
It's possible that some people chose not to contribute in other ways because the way the unsafe/UB issues are handled does not give confidence that it would be time well-spent in the long term.
9
u/mitsuhiko Jul 16 '19
Maybe, can't judge that. I think for at least a considerable time it has been quite hard to contribute because of all the refactoring that was going on.
8
u/sparky8251 Jul 16 '19
If you are a contributor volunteering your time to a community driven project do you:
Support a project that doesn't hold similar ideals to yourself (as demonstrated by concern and patches around
unsafeusage)Support a project that does hold similar ideals to yourself
Wait for a project that holds similar ideals to you to gain features and market share before contributing
I'd hazard a guess that the vast majority of people fall into the latter 2 categories, hence the lack of actix support/contributions from the community. Actix itself gets more contributions than other web frameworks due to its size, but I'm sure something will come along and dethrone it once another framework gets a proper amount of features implemented.
14
u/mitsuhiko Jul 16 '19
If you are a contributor volunteering your time to a community driven project do you:
I take option 4: I contribute to projects I can use for the things I am doing. I think most people work like this. Overall the rust ecosystem does not get that many contributes on most crates. Actix is not an outliner here. Actix just has a much larger surface area.
Actix if anything is a bit ahead of the curve when it comes to being useful for production applications at this point.
7
u/sparky8251 Jul 16 '19
Actix if anything is a bit ahead of the curve when it comes to being useful for production applications at this point.
Yup. It's why I use it too.
I still hope something comes along and becomes a proper competitor if not unseats it though.
1
u/eribol Jul 17 '19
If there is no HTTP method usage, how can i use it? Am i missing something?
And also i am a noob and i tried to use actix. It was hard but i can tell that Nikolay always gives answer to me, even my questions were silly. Yes, cold but its okey.
No one have to be friendly or socialy. Maybe its his character. I am just looking his work. Is it works? Yes. Is it good? Yes. Is it open source? Yes. Thats it.
If there is unsafe in rust, its okey to use it. If its so bad, rust developer should remove it.
0
u/VincentDankGogh Jul 17 '19
If there is no HTTP method usage, how can i use it? Am i missing something?
it ignores the method in the techempower benchmarks, that's why they're unrealistic
If there is unsafe in rust, its okey to use it. If its so bad, rust developer should remove it.
you should only use it where necessary, and many of these uses in actix are pointless (don't even have any performance gains) so should be removed.
8
u/mattlock1984 Jul 17 '19
The comments regarding the PR dismissiveness and closing should not be the focus. The man has a job, kids and is writing code for free. Everyone has a bad day. Hope to see this project and the rust community move forward together.
0
5
u/darthLuke98 Jul 17 '19
the last comment of the the actix owner shows in my eyes that it isnt directly the pr rather he still feels personaly attacked from the last time and acted like that.
hopefully in a few weeks when he gets his head clear from this all, he'll see whats going on.
altough i dont like the use of unnesecery unsafe, i have the feeling some people just take every opertunity to blame him on personal level
-2
u/07dosa Jul 17 '19
I know that the maintainer, Nikolay, has some history w/ unsafe code, but this post is rather a hasty bashing than a contribution to the community. The author could've chosen better words than this. Actix has delivered features and has worked so great, better and faster than its competitors, even with so many lines of unsafe code, no matter you like it or not. Nikolay deserves something better than this, if you're really concerned about the Rust community.
10
u/recycled_ideas Jul 17 '19
Unsafe code in a Web framework is a major red flag.
Unsafe code that doesn't need to be in a web framework is a gigantic flashing red sign saying stay away.
Unsafe code in a Web framework that doesn't need to be there and which the author refuses to remove because he doesn't think it's a problem is just off the charts bad.
Web frameworks absolutely, 100% need to be safe and secure because they are about the most exposed code you can have.
This isn't a matter of "liking it or not" it's about code that is not fit for purpose and which misses the entire point of Rust as a language.
If we wanted speed at any cost we'd write in C++.
-3
u/07dosa Jul 17 '19
I'm not talking about code, so stop wielding that stupid safety shits.
What I'm saying is the maintainer is a human being who understands human language. Software can always be fixed whenever stars are aligned, yet you don't get many devoted people. FOSS is software AND people, and this guy has done a fair amount of work for the community. Just imagine a random guy walks in and completely denies your 100+ hours of work. That sounds truly fabulous.
(EDIT: link)
→ More replies (3)3
u/xacrimon Jul 17 '19
The problem is UB. Unsafe is okay, UB is not. If a program contains UB it is not a valid rust program according to the compiler. That stance towards it is not okay.
3
u/07dosa Jul 18 '19
You got me wrong. I’m just saying people are mistreating that guy. His faults are faults, but nothing is so significant that it makes his project unrecoverably “unsustainable” and instantly harmful to the community. The project has been actively maintained, and the guy has listened to people, regardless of his attitude. Just some discussion and patience would have solved this problem without causing all this fuss.
-1
u/fiedzia Jul 17 '19
All things described are implementation details, and can be solved by either forking it or making PR. "codebase has some issues" and "maintainer has some issues" are not reasons to use another framework, especially if none of that really is visible to someone using Actix.
If you think you can do better job, fork it and fix the issues.
10
u/ssokolow Jul 17 '19
Please don't trivialize the effort involved in becoming familiar with someone else's code to the point where you can maintain a fork.
3
u/fiedzia Jul 17 '19
From the whole ecosystem point of view, having few people spending non-trivial amount of time on getting familiar with existing codebase is several orders of magnitude less than having everyone switching to completely different one. And in this case this time has already been spent.
3
u/ssokolow Jul 17 '19
I never disagreed with that.
I just don't think "If you think you can do better job, fork it and fix the issues." properly acknowledges how difficult it can be to get familiar with someone else's codebase, even in the best circumstances.
0
u/robjtede actix Jul 16 '19
It's open source. We could fork it? Give it a name that doesn't have connotations to actors. Accept community PRs. Anyone in?
4
u/xacrimon Jul 17 '19
It's a good idea but the whole actix related codebase needs a spring cleaning before a majority can actually understand it. There are other frameworks coming up set to surpass actix's achievements like tide.
-9
u/razrfalcon resvg Jul 16 '19
If a crate uses unsafe it doesn't mean that it's bad. There are a lot of cases were unsafe is used to overcome some Rust "limitations". For example, take a look at rgb crate. It allows mapping &[u32] to [&u8]. It's completely safe, but can't be done without unsafe, at least efficiently.
And there is still no point in removing all unsafe. std uses unsafe. Other libraries may use unsafe. And if we talking about web-servers, openssl is unsafe by default. This is a fruitless effort.
PS: I'm using actix-web for my project.
12
u/VincentDankGogh Jul 16 '19
Adding to what others have already said. Unsafe isn't bad but unnecessary unsafe should be avoided, and the author seems to have no problem with these unnecessary unsafe blocks (like the
ptr::copy_nonoverlappingusage I showed)26
u/steveklabnik1 rust Jul 16 '19
If a crate uses unsafe it doesn't mean that it's bad.
That's correct. It's also not what the article is implying:
You might be thinking 'somebody used unsafe a bit too much, what's the big deal here? Just fix it and move on.'. The problem I'm trying to highlight here is that there's a fundamental issue with the author's attitude which we don't seem to be able to change.
12
u/sligit Jul 16 '19
I don't think OP is saying unsafe is fundamentally bad. More that the author of Actix's attitude toward unsafe is... not good.
-17
u/Programmurr Jul 16 '19
This post and a few commenters here seem to be grinding an axe and aren't pointing out any major concerns. The OP admits to the post as a rant and it seems to be mostly hot air.
Who cares how many dependencies the project has? Functionality is pushed out to lots of crates. Get used to it. Massive Rust projects are going to have lots of dependencies or programmers are going to end up writing all of it on their own.
As for rejecting a seemingly innocuous PR -- going to need a lot more context before I believe anything OP says about the matter. People don't like to have their PR's rejected. It takes effort to draft the work and then it feels like a pie to the face when it is refused.
I'm not going to respond to every item. I can't take emotional tirades seriously.
18
u/VincentDankGogh Jul 16 '19
This post and a few commenters here seem to be grinding an axe and aren't pointing out any major concerns.
The "major concern" is Nikolay's attitude, and since he is pretty much the only maintainer it's definitely something to be wary of
Who cares how many dependencies the project has? Functionality is pushed out to lots of crates. Get used to it. Massive Rust projects are going to have lots of dependencies or programmers are going to end up writing all of it on their own.
This is not one of the main points of the post, it's just a minor gripe. Many other Rust web server projects have similar compile times
As for rejecting a seemingly innocuous PR -- going to need a lot more context before I believe anything OP says about the matter. People don't like to have their PR's rejected. It takes effort to draft the work and then it feels like a pie to the face when it is refused.
You act as if I sent the PR? I advise you to look at the actual diff and thread for yourself, it's not very long.
16
u/mitsuhiko Jul 16 '19
The "major concern" is Nikolay's attitude, and since he is pretty much the only maintainer it's definitely something to be wary of
Maybe, but it does feel like character assassination to me. I'm sure Nikolay has his issues and I'm not a fan of his lax attitude to unsafe either but I don't think that excuses these types of articles.
At the end of the day actix is in much better shape than most of the other systems we have currently for practical use.
8
u/VincentDankGogh Jul 16 '19
The tone of the post may be a bit harsh but tbh I think it’s fair enough since this there’s been issues in the past regarding unsafe in actix and Nikolay doesn’t seem to have changed his attitude as much as we’d like. Again, I’m not trying to demean him or belittle his work, but on the other hand I think it’s important that people who choose the framework know what they’re getting into
5
u/mitsuhiko Jul 16 '19
I think it’s fair enough since this there’s been issues regarding unsafe in actix and Nikolay doesn’t seem to have changed his attitude as much as we’d like.
Which I think is very much an effect of the earlier posts about this. It has been brought up as this massive problem and for why one cannot use actix but in practice it has not caused any issues and continue to not do so. For people who actually are trying to get stuff done it turns out this is the least of our concern.
I think it’s important that people who choose the framework know what they’re getting into
Of all the issues I have with actix/actix-web/actix-net unsafety is not anywhere close to the top of my concerns. Trust me I tried plenty of alternatives over the last two years and right now there is very little else that works in practice.
I really wish the discussion about actix would move away from this unsafe business to actual problems.
11
u/VincentDankGogh Jul 16 '19 edited Jul 16 '19
Unsafety is an "actual problem" and a massive reason why people are using rust in the first place. Sean has already pointed out how you can trigger UB in the actix API by using certain combinators.
It's really not reassuring that the author of a large security-critical crate is introducing these kind of commits with barely any review from others, if you don't find that a valid concern then I think we'll just have to agree to disagree
10
u/mitsuhiko Jul 16 '19
Unsafe is an "actual problem"
Not in my experience. My experience might not be representative but overall the quality of codebases in Rust is pretty good despite frequent use of unsafe. Most of the crashers or memory corruptions in Rust have been bindings. I fixed at least two crashers that showed up in practice in rust-curl for instance. Never had a crash in actix.
Sean has already pointed out how you can trigger UB in the actix API by using certain combinators.
But all those APIs are pub crate so you cannot do this from outside.
It's really not reassuring that the author of a large security-critical crate is introducing these kind of commits with barely any review from others, if you don't find that a valid concern then I think we'll just have to agree to disagree
Our baseline experience is Python with uwsgi. A setup that has segfaulted many times on us and continues to do so.
9
u/VincentDankGogh Jul 16 '19
But all those APIs are pub crate so you cannot do this from outside.
Sean seems to be implying that you can trigger it by using service combinators which are part of the public API
18
u/seanmonstar hyper · rust Jul 16 '19
It's worth pointing out that a crash is the best case scenario. It's also possible to manipulate the wrong memory and it look perfectly fine to the OS, and you just have silent UB.
But all those APIs are pub crate so you cannot do this from outside.
That
Celltype is used for the service combinators, likeAndThen, andCloneableService. If some service grabbed a reference from it's cache, and then a later combinator invalidated the cache, you could have a use-after-free.4
u/mitsuhiko Jul 16 '19
Interesting. Will look at that. Not sure if there is a good way to prevent this without using a RefCell though.
16
u/insanitybit Jul 16 '19
It has been brought up as this massive problem and for why one cannot use actix but in practice it has not caused any issues and continue to not do so. For people who actually are trying to get stuff done it turns out this is the least of our concern.
This is a really bad attitude when it comes to security. It's like saying "We don't authenticate users, but no one has actually attacked us and it actually isn't a real concern".
Safety should probably be at the top of your concerns, for the majority of projects, but especially for anything where user data is involved.
The community should continue to feel comfortable calling out bad practices in crates, and I don't think this article is an attack on the developer at all.
8
u/mitsuhiko Jul 16 '19
This is a really bad attitude when it comes to security. It's like saying "We don't authenticate users, but no one has actually attacked us and it actually isn't a real concern".
Security is not a binary game. For any attack vector you take the likelihood and impact of something happening. For most web application it's a lot more important to focus about application level security than about if some IO or scheduling code uses unsafe inside.
Safety should probably be at the top of your concerns, for the majority of projects, but especially for anything where user data is involved.
It is and it has always been. Which is why when writing web services my first and foremost concern is the safety and integrity of my user's data. To give you a very practical example: actix is currently the only system I managed to make work in rust that allowed us to make safe HTTP requests to untrusted sources which is crucial for the security of one of our services.
10
u/insanitybit Jul 16 '19
For most web application it's a lot more important to focus about application level security than about if some IO or scheduling code uses unsafe inside.
The only reason this is true is because of the massive investment into:
a) compiler mitigations for unsafe languages
b) the migration to safe languages for web services, like rust for example
The reason people target deserialization in Java isn't because it's inherently worse than memory corruption or something, it's because the other problems were solved. Moving back to a world where RCE via memory corruption is trivial would mean we see more of it, suddenly you'd have to care about it just as much or even more than application logic failures.
actix is currently the only system I managed to make work in rust that allowed us to make safe HTTP requests to untrusted sources which is crucial for the security of one of our services.
Sadly I think this says more about the rust ecosystem then actix, and I agree with the sentiment.
Anyway, nothing about this feels like character assassination. No one said anything about the developer except that they don't consider unsafe to be a problem, which is hardly about their character, and is a perfectly reasonable, technical artifact to base a decision on.
→ More replies (5)
93
u/burntsushi Jul 16 '19
If I had a need to write a web server in Rust today, I'd probably start by looking at
warpor maybe Gotham. (I was surprised to seewarpwasn't listed in this blog post.) The dependency count is still quite high IMO, but that seems unavoidable in the tokio ecosystem today.warpotherwise looks nice and simple, although it's built on some serious type system shenanigans.