Uday Shankar
2010-Nov-19 19:52 UTC
Frontend and backend data Not in sync when two requests are made one after other in quick succession
Hi, We have a web-console that run on rails, on the console we have a button to add a new entry and below it we show all the entries that are already present in a box. when we click on the button a request goes to the backend to add that entry, when that request is complete a pop-up comes with message that entry was successful or not. This feature has been working fine. Of late we have observed a bug. when we click on add a new entry and before that request is complete if we double click on an entry in the box to view the details of another entry, the pop-up still comes with success message but when go to the backend to verify if the entry was made or NOT, we dont find the new entry. Can anyone throw light on what could the possible reason be. This is my first post on this forum, hope i am not breaking any rule by asking this question here. Thanks, Uday. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2010-Nov-19 20:47 UTC
Re: Frontend and backend data Not in sync when two requests are made one after other in quick succession
On 19 November 2010 19:52, Uday Shankar <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, > > We have a web-console that run on rails, on the console we have a button > to add a new entry and below it we show all the entries that are already > present in a box. when we click on the button a request goes to the > backend to add that entry, when that request is complete a pop-up comes > with message that entry was successful or not. This feature has been > working fine. Of late we have observed a bug. > when we click on add a new entry and before that request is complete if > we double click on an entry in the box to view the details of another > entry, the pop-up still comes with success message but when go to the > backend to verify if the entry was made or NOT, we dont find the new > entry. > > Can anyone throw light on what could the possible reason be.Have a look in the log (log/development.log assuming running in development mode) to get more information about what is going on. Also you can use various methods to debug your code in order to understand the problem. See the Rails Guide on debugging if you are not familiar with these techniques. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Uday Shankar
2010-Nov-26 20:33 UTC
Re: Frontend and backend data Not in sync when two requests are made one after other in quick succes
Hi, I am fairly new to rails and ajax as well. I have hinch that the problem i am facing is related to ajax requests. During the first ajax call, adding a new entry to the data is requested but before this request is complete another ajax call is made to the access the same dataset to view one of the data content. I feel somewhere these two ajax calls gets interleaved and the backend data is not updated to make the new entry that was requested first. Please suggest a way to investigate how to trace the ajax calls and if there is any possibility of this hunch might be true. Thanks, Uday. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Nov-27 01:39 UTC
Re: Frontend and backend data Not in sync when two requests are made one after other in quick succes
On Nov 26, 8:33 pm, Uday Shankar <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, > > I am fairly new to rails and ajax as well. I have hinch that the problem > i am facing is related to ajax requests. During the first ajax call, > adding a new entry to the data is requested but before this request is > complete another ajax call is made to the access the same dataset to > view one of the data content. I feel somewhere these two ajax calls gets > interleaved and the backend data is not updated to make the new entry > that was requested first. Please suggest a way to investigate how to > trace the ajax calls and if there is any possibility of this hunch might > be true.It''s entirely possible that overlapping ajax calls could trigger a race condition. For example if your controller does foo = Foo.find(params[:id]) # change some attributes foo.save! And you have 2 requests that come in at close to the same time then the sequencing can look like 1: instance one does Foo.find 2: instance two does Foo.find 3: instance one updates and saves 4: instance two updates and saves, overwriting the changes made in 3. if you have a feeling that this might be the case, one thing that I sometimes find helpful is to insert a few sleeps into the app at strategic points so as to make the race condition more likely. Depending on what sort of stuff you are doing to your models, you may find optimistic locking useful Fred> > Thanks, > Uday. > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Uday Shankar
2010-Dec-04 10:25 UTC
Re: Frontend and backend data Not in sync when two requests are made one after other in quick succes
Thanks Fred, it was really helpful. To prevent the issue i have disabled the 2nd ajax call from the frontend. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.