Highlighted

Server side code runs twice on submit

Participant ,
Nov 13, 2019

Copy link to clipboard

Copied

I have a very simple page that the user scans a serial number barcode into a form, the form submits and adds a single entry into the SQL table. When we first built this site Firefox was causing duplicate entries on every submit. Switched to Chrome and it stopped. Now 18 months later and randomly (about 1 out of every 10) there's a duplicate entry when using Chrome or IE. The time stamp on the duplicate entry is fractions of a second later. As a test, I added a 5-second delay after the submission to make sure wasn't the page refreshing so fast that the barcode was scanned twice and still randomly we get duplicate entries. 

When the problem first happened in Firefox I found a post about a possible cause. Of course, I can't find it again.  I'm running CF 2016 with all the latest patches, Windows Server 2016 running IIS.

 

Thoughts?

You're probably referring to this issue with HTTP/2:

https://tracker.adobe.com/#/view/CF-4198446

 

Seems the solution is to install KB4093120 from Microsoft or disable HTTP/2.

 

TOPICS
Getting started

Views

473

Likes

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

Server side code runs twice on submit

Participant ,
Nov 13, 2019

Copy link to clipboard

Copied

I have a very simple page that the user scans a serial number barcode into a form, the form submits and adds a single entry into the SQL table. When we first built this site Firefox was causing duplicate entries on every submit. Switched to Chrome and it stopped. Now 18 months later and randomly (about 1 out of every 10) there's a duplicate entry when using Chrome or IE. The time stamp on the duplicate entry is fractions of a second later. As a test, I added a 5-second delay after the submission to make sure wasn't the page refreshing so fast that the barcode was scanned twice and still randomly we get duplicate entries. 

When the problem first happened in Firefox I found a post about a possible cause. Of course, I can't find it again.  I'm running CF 2016 with all the latest patches, Windows Server 2016 running IIS.

 

Thoughts?

You're probably referring to this issue with HTTP/2:

https://tracker.adobe.com/#/view/CF-4198446

 

Seems the solution is to install KB4093120 from Microsoft or disable HTTP/2.

 

TOPICS
Getting started

Views

474

Likes

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
Nov 13, 2019 0
LEGEND ,
Nov 13, 2019

Copy link to clipboard

Copied

Are you using the form submit, or are you using JavaScript or jQuery to submit the data?

 

V/r,

 

^ _ ^

Likes

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
Reply
Loading...
Nov 13, 2019 0
Participant ,
Nov 13, 2019

Copy link to clipboard

Copied

<!DOCTYPE html>
<head>
<title>Title Here</title>

<!--- Page sleep 2 seconds --->
<cfscript>
thread = CreateObject("java","java.lang.Thread");
thread.sleep(2000); // CF will now sleep for 2 seconds
</cfscript>

 <!--- Process Form --->
<cfif isdefined("Form.MAC") AND Form.MAC NEQ ''>
<!--- Set Session For Next Submit --->
<cfset session.select = '#form.type#'>
	
<!--- Update MAC --->
<cfset MAC = LCASE(#Form.MAC#)>

<!--- Check for existing MAC --->
<cfquery name="Dup" datasource="#session.xxx#">
Select MAC, Serial
From sometable
Where MAC = '#MAC#'
</cfquery>
 
<cfif Dup.recordcount EQ 0>
<!--- Insert MAC into table --->
<cfquery datasource="#session.xxx#">
INSERT Into sometable (MAC)
Values (
'#MAC#')
</cfquery>
  
<!--- Get NEW ID --->
<cfquery name="NID" datasource="#session.xxx#">
Select ID
From Sometable
Where MAC = '#MAC#'
</cfquery>

<!--- Create Serial Number --->
<cfset today=#Now()#>
<cfset Year = #DateFormat(Today, "yy")#>
<cfset Week = #DateFormat(Today, "ww")#>
<cfset ID = #Right(NID.ID, 3)#>
  
<!--- Update table with serial number --->
<cfquery datasource="#session.xxx#">
Update sometable
Set Serial = '#form.Type##Year##week##ID#'
Where MAC = '#MAC#'
</cfquery> 
  </cfif> 
</cfif>

<cfif isdefined("Form.MAC") AND Form.MAC NEQ '' AND isdefined("dup.recordcount") AND Dup.recordcount EQ 0>
<cfoutput><span class="BoldGreen">Serial Created: #form.Type##Year##week##ID#</cfoutput></span>
<cfelseif isdefined("dup.recordcount") AND Dup.recordcount EQ 1>
<span class="BoldRed">MAC Address Exists with Serial Number <cfoutput>#dup.serial#</cfoutput></span>
	</cfif>

<form id="form1" name="form1" method="post" action="">
 <p>
  <label for="Type">Player Type:</label>
  <select name="Type" id="type">
   <option value="B" <cfif isdefined("session.select") and session.select EQ 'B'>Selected</cfif>>Barix</option>
   <option value="P" <cfif isdefined("session.select") and session.select EQ 'P'>Selected</cfif>>On Premise NUC</option>
   <option value="S" <cfif isdefined("session.select") and session.select EQ 'S'>Selected</cfif>>Digital Signage NUC</option>
  </select>
 </p>
 <p>
  <label for="MAC">MAC:</label>
  <input type="text" name="MAC" id="MAC" autofocus />
 </p>
 <p>
  <input type="submit" name="submit" id="submit" value="Submit" />
 </p>
</form>

 

It's a basic form submit. This isn't the only page it's happening on. It's happening on forms across the site. 

Likes

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
Reply
Loading...
Nov 13, 2019 0
LEGEND ,
Nov 13, 2019

Copy link to clipboard

Copied

Well, I doubt it has anything to do with your code; although I do have some suggestions on how you code, if you don't mind hearing them.

 

Since it's not doing it 100% of the time, I'm inclined to think that the issue might be webserver related, or something else.  I'd also check the CFAdmin logs to see if anything weird is popping up.

 

V/r,

 

^ _ ^

Likes

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
Reply
Loading...
Nov 13, 2019 0
Participant ,
Nov 13, 2019

Copy link to clipboard

Copied

Always open to learning better ways to do things so suggest away. This is an internal site so I do skip over cfsqltype since there are only 3 users.

 

The doc I found when this first happened I somewhat remember the fix was server side and had to do with HTML 1.1 vs 2.0 or something similar.  There's nothing in the admin logs. I've dug through those.

Likes

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
Reply
Loading...
Nov 13, 2019 0
Explorer ,
Nov 14, 2019

Copy link to clipboard

Copied

You're probably referring to this issue with HTTP/2:

https://tracker.adobe.com/#/view/CF-4198446

 

Seems the solution is to install KB4093120 from Microsoft or disable HTTP/2.

 

Likes

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
Reply
Loading...
Nov 14, 2019 0
ghanna1 LATEST
Participant ,
Nov 14, 2019

Copy link to clipboard

Copied

Thank you. That was the article I needed. 

Likes

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
Reply
Loading...
Nov 14, 2019 0
LEGEND ,
Nov 13, 2019

Copy link to clipboard

Copied

Just very simple things like:

<cfset MAC = LCASE(#Form.MAC#)>

Should be:

<cfset MAC = LCASE(Form.MAC)>
or
<cfset MAC = LCASE("#Form.MAC#")>

 

<cfset today=#Now()#>
<cfset Year = #DateFormat(Today, "yy")#>
<cfset Week = #DateFormat(Today, "ww")#>
<cfset ID = #Right(NID.ID, 3)#>

 

Should be:

<cfset today=Now()>
<cfset Year = DateFormat(Today, "yy")>
<cfset Week = DateFormat(Today, "ww")>
<cfset ID = Right(NID.ID, 3)>

 

I no longer have the link to an article explaining why, but apparently using the hashtags on variables when they are not used in strings or for output can make your app/site run slower.

 

Also, there have been reported issues with IsDefined().  A better alternative would be to use StructKeyExists().

<cfif isdefined("Form.MAC") AND Form.MAC NEQ '' AND isdefined("dup.recordcount") AND Dup.recordcount EQ 0>

 

Should be:

<cfif StructKeyExists(Form,"MAC") AND Form.MAC NEQ '' AND StructKeyExists(dup,"recordcount") AND Dup.recordcount EQ 0>

 

If you want to check and see if a variable has been set:

<cfif StructKeyExists(variables,"myVar")>

 

I believe this will work on all scopes: queryName, variables, application, server, cgi, URL, etc.

 

V/r,

 

^ _ ^

Likes

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
Reply
Loading...
Nov 13, 2019 1
Participant ,
Nov 13, 2019

Copy link to clipboard

Copied

Thanks! I've used StructKeyExists before yet I always forget about it. 

Likes

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
Reply
Loading...
Nov 13, 2019 0