Uploaded image for project: 'Sakai'
  1. Sakai
  2. SAK-38933

BasicSqlService.getCal() returns shared Calendar objects, causing some thread-safety issues

    Details

    • Type: Bug
    • Status: CLOSED
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.6.x, 2.7.x
    • Fix Version/s: 2.6.x, 2.7.x, 2.8.x
    • Component/s: Kernel
    • Labels:
      None
    • CLE Team Issue:
      Yes
    • Previous Issue Keys:
      KNL-637

      Description

      Under some circumstances, the shared GregorianCalendar instance returned by the SqlService bean can cause exceptions to be thrown due to threading issues. This has been observed under modest concurrent load using the Oracle 11.1.0.7.0 driver, reading Timestamp columns. It is apparently driven by the ResultSet.getTimestamp(int, Calendar) signature in this case.

      However, any code that uses a SimpleDateFormat or a number of other non-thread-safe items against the shared Calendar instance are likely to throw an ArrayOutOfBoundsException. Some more detail is available here: http://jroller.com/dschneller/entry/calendar_dateformat_and_multi_threading

      It is also worth noting that the newest Oracle JDBC drivers (11.2.x) appear to handle the specific Timestamp field case, though we still have dangerous behavior in Sakai code.

      The best solution may be to return a clone in the getCal() method, rather than the reference to the instance variable. One snippet of Sakai code that should be changed follows:

      BasicSqlService.java:417 (trunk, r86933)

      /** Used to work with dates in GMT in the db. */
      protected final GregorianCalendar m_cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));

      /**

      • {@inheritDoc}

        */
        public GregorianCalendar getCal()
        {
        return m_cal;
        }


      For searchability of this ticket, a prototypical stack trace excerpt follows:

      org.sakaiproject.portal.api.PortalHandlerException: org.sakaiproject.tool.api.ToolException
      at org.sakaiproject.portal.charon.SkinnableCharonPortal.doGet(SkinnableCharonPortal.java:837)
      caused by: org.sakaiproject.tool.api.ToolException
      at org.sakaiproject.cheftool.ToolServlet.doGet(ToolServlet.java:236)
      caused by: java.lang.reflect.InvocationTargetException
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      caused by: java.lang.ArrayIndexOutOfBoundsException: 22
      at sun.util.calendar.BaseCalendar.getCalendarDateFromFixedDate(BaseCalendar.java:436)
      at java.util.GregorianCalendar.computeFields(GregorianCalendar.java:2081)
      at java.util.GregorianCalendar.computeTime(GregorianCalendar.java:2472)
      at java.util.Calendar.updateTime(Calendar.java:2468)
      at java.util.Calendar.getTimeInMillis(Calendar.java:1087)
      at oracle.jdbc.driver.DateTimeCommonAccessor.getTimestamp(DateTimeCommonAccessor.java:256)
      at oracle.jdbc.driver.OracleResultSetImpl.getTimestamp(OracleResultSetImpl.java:1089)
      at org.apache.commons.dbcp.DelegatingResultSet.getTimestamp(DelegatingResultSet.java:548)
      at org.sakaiproject.site.impl.DbSiteService$DbStorage.readSqlResultRecord(DbSiteService.java:2122)
      at org.sakaiproject.db.impl.BasicSqlService.dbRead(BasicSqlService.java:564)
      at org.sakaiproject.db.impl.BasicSqlService.dbRead(BasicSqlService.java:464)
      at org.sakaiproject.util.BaseDbFlatStorage.getSelectedResources(BaseDbFlatStorage.java:470)
      at org.sakaiproject.site.impl.DbSiteService$DbStorage.getSites(DbSiteService.java:782)
      at org.sakaiproject.site.impl.BaseSiteService.getSites(BaseSiteService.java:1621)
      at org.sakaiproject.site.cover.SiteService.getSites(SiteService.java:400)

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                dhorwitz David Horwitz
                Reporter:
                noahbotimer Noah Botimer
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Git Source Code