• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

CFLOCK and session vars

Guest
Feb 05, 2008 Feb 05, 2008

Copy link to clipboard

Copied

I am building a multiuser site with session vars. I understand the need for exclusive locking when writing session vars, but am a little confused when it comes to reading them. I have the need to use certain session vars within SQL queries, etc. I do need to use exclusive here as well, right? Also, Is this bad?



I'd rather not have a hundred cflock statements within my CFC functions, etc.

TOPICS
Advanced techniques

Views

466

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 05, 2008 Feb 05, 2008

Copy link to clipboard

Copied

> I am building a multiuser site with session vars.

Which CF version?


> I understand the need for
> exclusive locking when writing session vars,

One hasn't had to - intrinsically - do this since CF5.

Read the docs regarding when to lock shared-scope data:

http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=sharedVars_20.html


> Also, Is this
> bad? <cflock scope='session' timeout='30' type='exclusive'> <cfset mySess =
> session /> </cflock>

This will achieve little, as it will simply create a reference to the
session scaope, rather than a copy. All you're doing is referring to the
same shared-scope data (with the same potential issues) via a different
variable name.

On the whole, locking shared-scope data is far less of a concern since CF5
than it used to be.

If you want to do some reading, read the doc I pointed you to, and Google
CFLOCK. This conversation has been well documented several times in the
past (and at least ocne on these forums within the last month or so).

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Feb 07, 2008 Feb 07, 2008

Copy link to clipboard

Copied

This cannot be true. I am using CF8. Without an exclusive lock on both reading and writing my application's session variables I have witnessed my users getting their sessions mixed up.

Example: My users (average of 150 concurrent) all get content generated from a single SQL view, and we pass in their userId using cfqueryparam. If I do not wrap that query in an exclusive session lock, users randomly see results that are not meant for their eyes.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 07, 2008 Feb 07, 2008

Copy link to clipboard

Copied

That sounds like a problem with the variable scoping.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 07, 2008 Feb 07, 2008

Copy link to clipboard

Copied

> This cannot be true. I am using CF8. Without an exclusive lock on both
> reading and writing my application's session variables I have witnessed my

Session variables aren't shared *between users*. They're specific to a
user. The only time you're going to be getting contension with a session
variable is when a single user has two browser windows open hitting the
same site. If you've got some weird session bleeding between different
users, then <locking the session scope isn't going to help.

You're problem is something else, and your locking strategy is at best
dealing with it coincidentally. Which should be a bit of a concern...

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 07, 2008 Feb 07, 2008

Copy link to clipboard

Copied

> contension

Oh dear.

"contention".

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 07, 2008 Feb 07, 2008

Copy link to clipboard

Copied

> You're

Groan. I give up.

:-(

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 08, 2008 Feb 08, 2008

Copy link to clipboard

Copied

LATEST
Emadsen wrote:
If I do not wrap that query in an exclusive session lock, users randomly see results that are not meant for their eyes.

The answer might simply be to rename a variable into session.someResult. In fact, you could even do this:

<cfquery name="session.getOrderItem">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation