GMOD / docker-apollo

:whale: Apollo 2.X Docker Image
GNU General Public License v3.0
10 stars 12 forks source link

createUser REST exceptions #20

Closed epaule closed 5 years ago

epaule commented 7 years ago

creating 100 users with a rest call using the below script creates:

ERROR errors.GrailsExceptionResolver  - StaleObjectStateException occurred when processing request: [POST] /user/createUser
Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) : [org.bbop.apollo.User#117]. Stacktrace follows:
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) : [org.bbop.apollo.User#117]
    at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:198)
    at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
    at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
    at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
    at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
    at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
    at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
    at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
    at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

errors, whereas it doesn't with the groovy script add_users.groovy (with a CSV file).

#!/usr/bin/env ruby
require 'net/http'
require 'uri'
require 'json'

# contains hardcoded crud
def rest_call(url,params)
  uri = URI.parse('http://localhost:8888/'+url)
  header = {'Content-Type': 'application/json'}
  params.merge!({'username' => 'admin@local.host','password' => 'password'})

  http = Net::HTTP.new(uri.host,uri.port)
  request = Net::HTTP::Post.new(uri.request_uri,header)
  request.body = params.to_json

  response = http.request(request)

  puts response.message if response.code != '200'

end

# creates users, organisms and sets the permisstion to rw
1.upto(100){|n|
       user = "student#{n}"
       username = user+'@test.tst'
       params = {
        'email'    => username,
        'firstName'=> user,
        'lastName' => 'test',
        'newPassword' => 'password',
        'role' => 'user'
       }
       rest_call('user/createUser',params)
}
nathandunn commented 7 years ago

Thanks @epaule I'll take a look at it next week. Off the top of my head, though, I don't see any problem with your script. Is it possible for you to use the groovy script instead for this?

https://github.com/GMOD/Apollo/blob/master/docs/web_services/examples/groovy/add_users.groovy

epaule commented 7 years ago

hmm ... seems to be limited to running it on the same host (localhost). As soon as I introduce a bit of network lag, it manages to process the transactions in line.

nathandunn commented 5 years ago

Sorry this got delayed. Another user had brought up this inefficiency as well and we ended up fixing it in develop https://github.com/GMOD/Apollo/issues/2105