https://redmine.gc.cuny.edu/https://redmine.gc.cuny.edu/favicon.ico2019-10-21T16:37:56ZCUNY Graduate Center - Project Tracking SystemCUNY Academic Commons - Bug #11997: Domain mapping not working for CETLS sitehttps://redmine.gc.cuny.edu/issues/11997?journal_id=461222019-10-21T16:37:56ZBoone Gorgesboone@gorg.es
<ul><li><strong>Assignee</strong> set to <i>Raymond Hoh</i></li></ul><p>Ray, I've begun looking at this but I have a limited understanding of how mapping is intended to work. I can see that the redirect_canonical() function is incorrectly flagging that cetls.bmcc.cuny.edu be redirected to bmcccetls.commons, but I haven't figured out how or why yet. I'll continue to look, but if you can, I'd like you to jump in to see if you can identify what's happening.</p> CUNY Academic Commons - Bug #11997: Domain mapping not working for CETLS sitehttps://redmine.gc.cuny.edu/issues/11997?journal_id=461232019-10-21T16:48:40ZBoone Gorgesboone@gorg.es
<ul></ul><p>On a lark, I flushed the object cache, and the redirect behavior corrected itself.</p>
<p>This, along with backtrack info I collected, suggests strongly to me that:<br />- A call to `home_url()` in `redirect_canonical()` was incorrectly returning bmcccetls.commons instead of the mapped domain, which was triggering the redirect<br />- `home_url()` was returning the wrong value because the `domain_mapping_siteurl()` filter callback was not working properly<br />- This was probably caused by domain_mapping_get_data_by_id() incorrectly returning a null result for the blog ID<br />- Since this was fixed by a cache flush (and everything looks OK in the database tables) it means that a null result for the blog ID must have been incorrectly stored in the cache.</p>
<p>If this reasoning is correct, the questions are (a) why did a bad value get cached, and (b) are there techniques we can put into place to mitigate this sort of problem in the future? Even if it means not caching null values (ie forcing a database hit for non-mapped domains)? Ray, any thoughts you have would be welcome.</p> CUNY Academic Commons - Bug #11997: Domain mapping not working for CETLS sitehttps://redmine.gc.cuny.edu/issues/11997?journal_id=461262019-10-21T16:53:08ZGina Cherry
<ul></ul><p>Thanks so much for the very quick response! Thankfully, I can now send out the weekly CETLS newsletter with links to our blog and events.</p> CUNY Academic Commons - Bug #11997: Domain mapping not working for CETLS sitehttps://redmine.gc.cuny.edu/issues/11997?journal_id=461272019-10-21T18:24:46ZRaymond Hoh
<ul></ul><p>Boone, can you pass me the backtrace log if you still have it?</p>
<p>If not, no problem. I'll take a closer look.</p> CUNY Academic Commons - Bug #11997: Domain mapping not working for CETLS sitehttps://redmine.gc.cuny.edu/issues/11997?journal_id=461282019-10-21T18:28:57ZBoone Gorgesboone@gorg.es
<ul><li><strong>File</strong> <a href="/attachments/12758">11997-backtrace.txt</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/12758/11997-backtrace.txt">11997-backtrace.txt</a> added</li></ul><p>Sure thing, Ray. See attached for a relevant backtrace of the redirect_canonical call.</p> CUNY Academic Commons - Bug #11997: Domain mapping not working for CETLS sitehttps://redmine.gc.cuny.edu/issues/11997?journal_id=461542019-10-22T18:22:31ZRaymond Hoh
<ul><li><strong>Category name</strong> set to <i>Domain Mapping</i></li><li><strong>Status</strong> changed from <i>New</i> to <i>Staged for Production Release</i></li><li><strong>Target version</strong> set to <i>1.15.13</i></li></ul><blockquote>
<p>If this reasoning is correct, the questions are (a) why did a bad value get cached, and (b) are there techniques we can put into place to mitigate this sort of problem in the future? Even if it means not caching null values (ie forcing a database hit for non-mapped domains)? Ray, any thoughts you have would be welcome.</p>
</blockquote>
<p>Boone, your reasoning is correct. I've attempted to fix this in the following changeset:<br /><a class="external" href="https://github.com/cuny-academic-commons/cac/commit/62372e10b9d3d5704f00037724f2064a0415ef65">https://github.com/cuny-academic-commons/cac/commit/62372e10b9d3d5704f00037724f2064a0415ef65</a></p>
<p>For (a), this was an oversight on my end. Previously, I cached invalid DB results from <code>domain_mapping_get_data_by_id()</code> as <code>null</code> to prevent checking the DB again for the same data:<br /><a class="external" href="https://github.com/cuny-academic-commons/cac/blob/0c1c5eb4a0d957cbb9af5c4dc4c6e2a10ab51705/wp-content/plugins/wordpress-mu-domain-mapping/domain_mapping.php#L604">https://github.com/cuny-academic-commons/cac/blob/0c1c5eb4a0d957cbb9af5c4dc4c6e2a10ab51705/wp-content/plugins/wordpress-mu-domain-mapping/domain_mapping.php#L604</a></p>
<p>However, if there is a <code>null</code> result, that means there was a problem connecting to the DB in the first place. Based on your stacktrace, you're correct that the <code>home_url()</code> would return the subdomain instead of the mapped domain URL.</p>
<p>For (b), I've made it so that we only cache valid results in the in the <code>domain_mapping_get_data_by_id()</code> function. Next, if there is a <code>null</code> value returned by the function, we try to return what is expected by comparing the current server's "HTTP_HOST" value. I tested this out locally and this appears to alleviate the infinite redirect loop. It's not entirely accurate, but this should help until the DB is able to return a proper result.</p>
<p>Let me know what you think.</p> CUNY Academic Commons - Bug #11997: Domain mapping not working for CETLS sitehttps://redmine.gc.cuny.edu/issues/11997?journal_id=461662019-10-22T19:38:58ZBoone Gorgesboone@gorg.es
<ul></ul><p>Thanks for the careful thinking about this, Ray. Knowing that a <code>null</code> result corresponds to a DB connection error is helpful. I'm happy to go ahead with your fix. Do you think this warrants a hotfix? It's a severe problem but it appears to be extremely rare.</p> CUNY Academic Commons - Bug #11997: Domain mapping not working for CETLS sitehttps://redmine.gc.cuny.edu/issues/11997?journal_id=462742019-10-24T19:37:57ZRaymond Hoh
<ul></ul><p>It's a good thing I didn't push the update as a hotfix because I found a bug that caused a redirect loop in the admin area as a result of the previous change:<br /><a class="external" href="https://github.com/cuny-academic-commons/cac/commit/eaaa6af50fa399026fa8c9cc12c7a2a96ec937e6">https://github.com/cuny-academic-commons/cac/commit/eaaa6af50fa399026fa8c9cc12c7a2a96ec937e6</a></p>
<p>I think that because the redirect loop is a rare occurrence, we can hold off until the next maintenance release.</p> CUNY Academic Commons - Bug #11997: Domain mapping not working for CETLS sitehttps://redmine.gc.cuny.edu/issues/11997?journal_id=462752019-10-24T19:39:55ZGina Cherry
<ul></ul><p>That's funny - I was going to report that, but when I went in today to make sure I had the details correct, it was no longer happening. I guess that's because you fixed it!</p> CUNY Academic Commons - Bug #11997: Domain mapping not working for CETLS sitehttps://redmine.gc.cuny.edu/issues/11997?journal_id=465522019-11-12T15:38:39ZBoone Gorgesboone@gorg.es
<ul><li><strong>Status</strong> changed from <i>Staged for Production Release</i> to <i>Resolved</i></li></ul>