Skip to content

Commit

Permalink
Use UUID directly for generating session IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
ldaley committed Apr 23, 2019
1 parent 259717a commit f2b63eb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Expand Up @@ -194,6 +194,7 @@ SessionStore sessionStoreAdapter(@Named(LOCAL_MEMORY_SESSION_CACHE_BINDING_NAME)
}

@Provides
@Singleton
SessionIdGenerator sessionIdGenerator() {
return new DefaultSessionIdGenerator();
}
Expand Down
Expand Up @@ -16,18 +16,17 @@

package ratpack.session.internal;

import com.google.inject.Singleton;
import io.netty.util.AsciiString;
import ratpack.session.SessionIdGenerator;

import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

@Singleton
public class DefaultSessionIdGenerator implements SessionIdGenerator {

public AsciiString generateSessionId() {
ThreadLocalRandom random = ThreadLocalRandom.current();
UUID uuid = new UUID(random.nextLong(), random.nextLong());
return AsciiString.of(uuid.toString());
return AsciiString.cached(UUID.randomUUID().toString());

This comment has been minimized.

Copy link
@erdi

erdi Apr 23, 2019

Member

You are aware that UUID.randomUUID() is potentially blocking, right? At least according to this and this.

This comment has been minimized.

Copy link
@ldaley

ldaley Apr 23, 2019

Author Member

It's not on Java 8+ for most environments. JDK 8 removed synchronized and now /dev/urandom (non blocking is used).

This comment has been minimized.

Copy link
@erdi

erdi Apr 23, 2019

Member

Oh, right. Thanks for the explanation.

}

}

0 comments on commit f2b63eb

Please sign in to comment.