This isn't correct. The birthday paradox models a situation of choices
*with replacement* from a set. That is, when multiple entities can have
the same value. We don't have replacement. You have a set of X active
sessions, all unique (since that's a database constraint) and somebody
is trying to guess one of them at random. So the probability is X/N, not
something approaching sqrt(N)/N.
Once a session has been created and saved successfully to the database,
it's known to be unique amongst all active sessions.
I'm not saying there's no issue here, but accuracy is important.
[...]
> 3) Clear session on logout: http://code.djangoproject.com/ticket/6941
>
> Currently sessions are not related to users. As discussed before, one-
> way relation is useful, i.e. users are related to sessions and
> sessions are cleared if they logout or if they login and a different
> user was logged in previously. This depends on #7515.
As discussed in the earlier thread, deleting sessions on logout is
almost certainly the right solution to this.
Regards,
Malcolm
I don't really know a nice way of saying this, so I'll trust you to
understand that I don't mean to be a dick.
You don't get to decide what's in scope for 1.0 and what isn't.
You're completely right that these tickets fall into the "bug"
category (though there's some feature-creep with #7515), which makes
them likely candidates. Still, you don't get to make a unilateral
decision here. I appreciate that you think these features are vital,
but you must understand that *everyone* has his or her own "must have"
list, and if we're to meet deadlines some people are inevitably going
to be disappointed.
So: please feel free to *suggest* that tickets be closed for 1.0; feel
free to *argue* for them... but stop demanding.
Further, if you've looked at the roadmap you'll see that we're two
weeks out from 1.0 alpha, which is a major deadline for newforms-admin
and a couple of other thorny issues. This means that all eyes are
going to be on finishing those features, and *not* on bug fixes --
we'll be focusing on those after feature freeze.
As I said, though, these are very likely candidates for 1.0. So the
best thing for you to do is tag them with the 1.0 milestone and wait a
couple weeks until we start focusing on bug fixes.
Jacob
That comment has no bearing.
(1) We pick a random session key.
(2) We save it to the database, where it should be unique, otherwise an
error is raised.
(3) We use that session key to pass back to the user.
At this point, the birthday paradox no longer applies. (3) should not
happen before (2). If it does, it's a bug that should be fixed, but the
database should be being used to guarantee uniqueness here. It's the
same database across all threads/processes/machines.
Your comment in that ticket avoids step (2), which is a necessary
uniqueness constraint.
Malcolm
Log in to trac.
See discussion here:
http://groups.google.com/group/django-developers/browse_thread/thread/560c324325723ba1/147c30570e4216d1?lnk=gst&q=spam#147c30570e4216d1
Yes. It's important to view things like this thread in the context of
the earlier thread about session fixes. There are a number of
inter-related things here and a fix that solves the general problem
instead of playing whack-a-mole is in order. Part of that, and implicit
in this whole thing, is ensuring that the new session id is saved (and
*created*) immediately to avoid collisions. The database is the only way
to ensure uniqueness here and there is a bug at that level. Increasing
some value from 32 bits to 64 bits is only changing some probabilities;
it's not actually solving the problem, just moving the goalposts to make
it harder to score an own goal. The rest of the conversation should
proceed on the assumption that the bug about creating unique database
entries will be fixed first.
Regards,
Malcolm
Now I think that the problem is only exists if one uses
non-transactional DB setup. In this case
due to race conditions one of the two simultaneous get_or_create calls
will "get" instead of "create". In a transactional setup one of the
transactions will fail to commit eventually since both get_or_create
will try to do INSERT not seeing each other. May be the fix then will be
to always use explicit INSERT instead of get_or_create and let it fail
on unique constraint?
P.S. Did I miss it in the thread or nobody talks about non-DB session
storages?
Not quite. The root problem is that get_or_create() is simply not
designed at the moment to enforce the "create" side. It assumes that if
another process creates the object during the call, then it's fine to
get the result and carry on. The idea is that after you call it, the
object exists in the database and you have a reference to the copy, not
that *only* get or *only* create will be called. This is why two people
can end up retrieving the same session object. There needs to be a path
that says "this must create if it isn't already there". That's a bug
that will be fixed.
> May be the fix then will be
> to always use explicit INSERT instead of get_or_create and let it fail
> on unique constraint?
That is the fix. It was discussed in the thread a couple of months ago.
When I've done my high priority tasks, I'll get around to adding the
ability to force insert or update at the model save level and the rest
falls out naturally. It's easy and I have a patch that mostly works. But
I need to review it again and it's in the queue.
It's almost like we need some kind of ticket tracking system so that
these things don't get lost and people won't start threads saying "look
at mine! look at mine!" Oh, wait ... we do have one of those. :-(
> P.S. Did I miss it in the thread or nobody talks about non-DB session
> storages?
It's more or less a side-issue that we'll work out as we go along. If
non-db storages have a way of enforcing uniqueness, we'll use it (and
that does require some effort to do -- I'm not dismissing them).
However, the storage is the only reliable place to enforce uniqueness,
so if the storage cannot guarantee it, Django can only work with what
it's given. So, for example, file storage might have problems on some
filesystems that don't have good locking semantics. Then it's a case of
"go buy yourself a real filesystem".
Regards,
Malcolm
Sorry. That was uncalled for on my part. I'm feeling buried under too
many active threads, but I didn't need to take it out on the people in
this one.
Malcolm
Thanks
Simon